Incorporate review

This commit is contained in:
Brendan Abolivier 2019-11-08 10:34:09 +00:00
parent b9cba07962
commit b16fa43386
No known key found for this signature in database
GPG Key ID: 1E015C145F1916CD

View File

@ -877,10 +877,10 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
# If we're not filtering on a label, then joining on event_labels will # If we're not filtering on a label, then joining on event_labels will
# return as many row for a single event as the number of labels it has. To # return as many row for a single event as the number of labels it has. To
# avoid this, only join if we're filtering on at least one label. # avoid this, only join if we're filtering on at least one label.
join_clause = ( join_clause = """
"LEFT JOIN event_labels" LEFT JOIN event_labels
" USING (event_id, room_id, topological_ordering)" USING (event_id, room_id, topological_ordering)
) """
if len(event_filter.labels) > 1: if len(event_filter.labels) > 1:
# Using DISTINCT in this SELECT query is quite expensive, because it # Using DISTINCT in this SELECT query is quite expensive, because it
# requires the engine to sort on the entire (not limited) result set, # requires the engine to sort on the entire (not limited) result set,
@ -890,14 +890,14 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
# the results. # the results.
select_keywords += "DISTINCT" select_keywords += "DISTINCT"
sql = ( sql = """
"%(select_keywords)s event_id, topological_ordering, stream_ordering" %(select_keywords)s event_id, topological_ordering, stream_ordering
" FROM events" FROM events
" %(join_clause)s" %(join_clause)s
" WHERE outlier = ? AND room_id = ? AND %(bounds)s" WHERE outlier = ? AND room_id = ? AND %(bounds)s
" ORDER BY topological_ordering %(order)s," ORDER BY topological_ordering %(order)s,
" stream_ordering %(order)s LIMIT ?" stream_ordering %(order)s LIMIT ?
) % { """ % {
"select_keywords": select_keywords, "select_keywords": select_keywords,
"join_clause": join_clause, "join_clause": join_clause,
"bounds": bounds, "bounds": bounds,