From d04271af7596fde06bbd8d0927be7e096e1d9d13 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 7 Jan 2021 08:08:12 -0800 Subject: [PATCH 1/2] Adds field on import job to check if job completed the task isn't a reliable indicator, unfortunately. --- bookwyrm/goodreads_import.py | 2 ++ bookwyrm/migrations/0034_importjob_complete.py | 18 ++++++++++++++++++ bookwyrm/models/import_job.py | 1 + bookwyrm/templates/import_status.html | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 bookwyrm/migrations/0034_importjob_complete.py diff --git a/bookwyrm/goodreads_import.py b/bookwyrm/goodreads_import.py index 9b8a4f01..5c982764 100644 --- a/bookwyrm/goodreads_import.py +++ b/bookwyrm/goodreads_import.py @@ -69,3 +69,5 @@ def import_data(job_id): item.save() finally: create_notification(job.user, 'IMPORT', related_import=job) + job.complete = True + job.save() diff --git a/bookwyrm/migrations/0034_importjob_complete.py b/bookwyrm/migrations/0034_importjob_complete.py new file mode 100644 index 00000000..14170607 --- /dev/null +++ b/bookwyrm/migrations/0034_importjob_complete.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2021-01-07 16:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0033_siteinvite_created_date'), + ] + + operations = [ + migrations.AddField( + model_name='importjob', + name='complete', + field=models.BooleanField(default=False), + ), + ] diff --git a/bookwyrm/models/import_job.py b/bookwyrm/models/import_job.py index 1ebe9b31..b10651b9 100644 --- a/bookwyrm/models/import_job.py +++ b/bookwyrm/models/import_job.py @@ -42,6 +42,7 @@ class ImportJob(models.Model): created_date = models.DateTimeField(default=timezone.now) task_id = models.CharField(max_length=100, null=True) include_reviews = models.BooleanField(default=True) + complete = models.BooleanField(default=False) privacy = models.CharField( max_length=255, default='public', diff --git a/bookwyrm/templates/import_status.html b/bookwyrm/templates/import_status.html index 6bb903b0..077cd3fb 100644 --- a/bookwyrm/templates/import_status.html +++ b/bookwyrm/templates/import_status.html @@ -8,7 +8,7 @@

Import started: {{ job.created_date | naturaltime }}

- {% if task.successful %} + {% if job.complete %}

Import completed: {{ task.date_done | naturaltime }}

From 9a114e1736db12f01f08e8f1fd7c0485f49cb917 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 7 Jan 2021 09:26:05 -0800 Subject: [PATCH 2/2] Don't match arbitrary results on empty isbn queries --- bookwyrm/connectors/abstract_connector.py | 7 ++++++- bookwyrm/connectors/self_connector.py | 2 ++ bookwyrm/views.py | 7 +++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index d63bd135..ab9900a7 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -34,10 +34,15 @@ class AbstractMinimalConnector(ABC): for field in self_fields: setattr(self, field, getattr(info, field)) - def search(self, query, min_confidence=None):# pylint: disable=unused-argument + def search(self, query, min_confidence=None): ''' free text search ''' + params = {} + if min_confidence: + params['min_confidence'] = min_confidence + resp = requests.get( '%s%s' % (self.search_url, query), + params=params, headers={ 'Accept': 'application/json; charset=utf-8', 'User-Agent': settings.USER_AGENT, diff --git a/bookwyrm/connectors/self_connector.py b/bookwyrm/connectors/self_connector.py index 0c21e7bc..c5d58a59 100644 --- a/bookwyrm/connectors/self_connector.py +++ b/bookwyrm/connectors/self_connector.py @@ -13,6 +13,8 @@ class Connector(AbstractConnector): ''' instantiate a connector ''' def search(self, query, min_confidence=0.1): ''' search your local database ''' + if not query: + return [] # first, try searching unqiue identifiers results = search_identifiers(query) if not results: diff --git a/bookwyrm/views.py b/bookwyrm/views.py index 5c5934dd..cc45bfb2 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -258,10 +258,12 @@ def get_activity_feed( def search(request): ''' that search bar up top ''' query = request.GET.get('q') + min_confidence = request.GET.get('min_confidence', 0.1) if is_api_request(request): # only return local book results via json so we don't cause a cascade - book_results = connector_manager.local_search(query) + book_results = connector_manager.local_search( + query, min_confidence=min_confidence) return JsonResponse([r.json() for r in book_results], safe=False) # use webfinger for mastodon style account@domain.com username @@ -278,7 +280,8 @@ def search(request): similarity__gt=0.5, ).order_by('-similarity')[:10] - book_results = connector_manager.search(query) + book_results = connector_manager.search( + query, min_confidence=min_confidence) data = { 'title': 'Search Results', 'book_results': book_results,