From 557f78eb027ee320140a5d29ee4a40a8e861a014 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 23 Sep 2017 11:04:26 -0700 Subject: [PATCH] Integrate author search into the query instead of postprocessing. Much faster this way. --- etiquette/photodb.py | 7 ++++--- etiquette/searchhelpers.py | 13 ++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/etiquette/photodb.py b/etiquette/photodb.py index d02ba17..29a1b14 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -728,6 +728,7 @@ class PDBPhotoMixin: notnulls, minimums, maximums, + author_ids=authors, mmf_results=mmf_results, ) print(query[:200]) @@ -765,9 +766,9 @@ class PDBPhotoMixin: #print('Failed mimetype') continue - if authors and photo.author_id not in authors: - #print('Failed author') - continue + # if authors and photo.author_id not in authors: + # #print('Failed author') + # continue if filename_tree and not filename_tree.evaluate(photo.basename.lower()): #print('Failed filename') diff --git a/etiquette/searchhelpers.py b/etiquette/searchhelpers.py index b23d8fe..932b38f 100644 --- a/etiquette/searchhelpers.py +++ b/etiquette/searchhelpers.py @@ -6,10 +6,21 @@ from . import objects from voussoirkit import expressionmatch -def build_query(orderby, notnulls, minimums, maximums, mmf_results=None): +def build_query( + orderby, + notnulls, + minimums, + maximums, + author_ids=None, + mmf_results=None, + ): query = ['SELECT * FROM photos'] wheres = [] + if author_ids: + notnulls.add('author_id') + wheres.append('author_id in %s' % helpers.sql_listify(author_ids)) + if mmf_results: wheres.append('id %s %s' % (mmf_results['operator'], helpers.sql_listify(mmf_results['photoids'])))