Make wheres a set instead of list.

This commit is contained in:
voussoir 2017-09-23 11:20:38 -07:00
parent 163e960bfa
commit 855e94ed87

View file

@ -15,14 +15,15 @@ def build_query(
mmf_results=None,
):
query = ['SELECT * FROM photos']
wheres = []
wheres = set()
if author_ids:
notnulls.add('author_id')
wheres.append('author_id in %s' % helpers.sql_listify(author_ids))
wheres.add('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'])))
# "id IN/NOT IN (1, 2, 3)"
wheres.add('id %s %s' % (mmf_results['operator'], helpers.sql_listify(mmf_results['photoids'])))
if orderby:
orderby = [o.split('-') for o in orderby]
@ -33,17 +34,20 @@ def build_query(
if column != 'RANDOM()':
notnulls.add(column)
for column in notnulls:
wheres.append(column + ' IS NOT NULL')
for (column, value) in minimums.items():
wheres.append(column + ' >= ' + str(value))
if minimums:
for (column, value) in minimums.items():
wheres.add(column + ' >= ' + str(value))
for (column, value) in maximums.items():
wheres.append(column + ' <= ' + str(value))
if maximums:
for (column, value) in maximums.items():
wheres.add(column + ' <= ' + str(value))
## Assemble
for column in notnulls:
wheres.add(column + ' IS NOT NULL')
if wheres:
wheres = 'WHERE ' + ' AND '.join(wheres)
query.append(wheres)