Make wheres a set instead of list.
				
					
				
			This commit is contained in:
		
							parent
							
								
									163e960bfa
								
							
						
					
					
						commit
						855e94ed87
					
				
					 1 changed files with 13 additions and 9 deletions
				
			
		|  | @ -15,14 +15,15 @@ def build_query( | ||||||
|         mmf_results=None, |         mmf_results=None, | ||||||
|     ): |     ): | ||||||
|     query = ['SELECT * FROM photos'] |     query = ['SELECT * FROM photos'] | ||||||
|     wheres = [] |     wheres = set() | ||||||
| 
 | 
 | ||||||
|     if author_ids: |     if author_ids: | ||||||
|         notnulls.add('author_id') |         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: |     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: |     if orderby: | ||||||
|         orderby = [o.split('-') for o in orderby] |         orderby = [o.split('-') for o in orderby] | ||||||
|  | @ -33,17 +34,20 @@ def build_query( | ||||||
|         if column != 'RANDOM()': |         if column != 'RANDOM()': | ||||||
|             notnulls.add(column) |             notnulls.add(column) | ||||||
| 
 | 
 | ||||||
|     for column in notnulls: |  | ||||||
|         wheres.append(column + ' IS NOT NULL') |  | ||||||
| 
 | 
 | ||||||
|  |     if minimums: | ||||||
|         for (column, value) in minimums.items(): |         for (column, value) in minimums.items(): | ||||||
|         wheres.append(column + ' >= ' + str(value)) |             wheres.add(column + ' >= ' + str(value)) | ||||||
| 
 | 
 | ||||||
|  |     if maximums: | ||||||
|         for (column, value) in maximums.items(): |         for (column, value) in maximums.items(): | ||||||
|         wheres.append(column + ' <= ' + str(value)) |             wheres.add(column + ' <= ' + str(value)) | ||||||
| 
 | 
 | ||||||
|     ## Assemble |     ## Assemble | ||||||
| 
 | 
 | ||||||
|  |     for column in notnulls: | ||||||
|  |         wheres.add(column + ' IS NOT NULL') | ||||||
|  | 
 | ||||||
|     if wheres: |     if wheres: | ||||||
|         wheres = 'WHERE '  + ' AND '.join(wheres) |         wheres = 'WHERE '  + ' AND '.join(wheres) | ||||||
|         query.append(wheres) |         query.append(wheres) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue