mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-28 23:20:09 +03:00
More efficient notif count queries
This commit is contained in:
parent
302fbd218d
commit
2ac516850b
2 changed files with 48 additions and 8 deletions
|
@ -39,6 +39,14 @@ class EventPushActionsStore(SQLBaseStore):
|
||||||
columns=["user_id", "stream_ordering"],
|
columns=["user_id", "stream_ordering"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.register_background_index_update(
|
||||||
|
"event_push_actions_highlights_index",
|
||||||
|
index_name="event_push_actions_highlights_index",
|
||||||
|
table="event_push_actions",
|
||||||
|
columns=["user_id", "room_id", "topological_ordering", "stream_ordering"],
|
||||||
|
where_clause="highlight=1"
|
||||||
|
)
|
||||||
|
|
||||||
def _set_push_actions_for_event_and_users_txn(self, txn, event, tuples):
|
def _set_push_actions_for_event_and_users_txn(self, txn, event, tuples):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
|
@ -88,8 +96,9 @@ class EventPushActionsStore(SQLBaseStore):
|
||||||
topological_ordering, stream_ordering
|
topological_ordering, stream_ordering
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# First get number of notifications
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT sum(notif), sum(highlight)"
|
"SELECT count(*)"
|
||||||
" FROM event_push_actions ea"
|
" FROM event_push_actions ea"
|
||||||
" WHERE"
|
" WHERE"
|
||||||
" user_id = ?"
|
" user_id = ?"
|
||||||
|
@ -99,13 +108,27 @@ class EventPushActionsStore(SQLBaseStore):
|
||||||
|
|
||||||
txn.execute(sql, (user_id, room_id))
|
txn.execute(sql, (user_id, room_id))
|
||||||
row = txn.fetchone()
|
row = txn.fetchone()
|
||||||
if row:
|
notify_count = row[0] if row else 0
|
||||||
return {
|
|
||||||
"notify_count": row[0] or 0,
|
# Now get the number of highlights
|
||||||
"highlight_count": row[1] or 0,
|
sql = (
|
||||||
}
|
"SELECT count(*)"
|
||||||
else:
|
" FROM event_push_actions ea"
|
||||||
return {"notify_count": 0, "highlight_count": 0}
|
" WHERE"
|
||||||
|
" highlight = 1"
|
||||||
|
" AND user_id = ?"
|
||||||
|
" AND room_id = ?"
|
||||||
|
" AND %s"
|
||||||
|
) % (lower_bound(token, self.database_engine, inclusive=False),)
|
||||||
|
|
||||||
|
txn.execute(sql, (user_id, room_id))
|
||||||
|
row = txn.fetchone()
|
||||||
|
highlight_count = row[0] if row else 0
|
||||||
|
|
||||||
|
return {
|
||||||
|
"notify_count": notify_count,
|
||||||
|
"highlight_count": highlight_count,
|
||||||
|
}
|
||||||
|
|
||||||
ret = yield self.runInteraction(
|
ret = yield self.runInteraction(
|
||||||
"get_unread_event_push_actions_by_room",
|
"get_unread_event_push_actions_by_room",
|
||||||
|
|
17
synapse/storage/schema/delta/39/event_push_index.sql
Normal file
17
synapse/storage/schema/delta/39/event_push_index.sql
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/* Copyright 2016 OpenMarket Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
INSERT INTO background_updates (update_name, progress_json) VALUES
|
||||||
|
('event_push_actions_highlights_index', '{}');
|
Loading…
Reference in a new issue