Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
3cc7f43e
Unverified
Commit
3cc7f43e
authored
4 years ago
by
Brendan Abolivier
Browse files
Options
Downloads
Patches
Plain Diff
Fix summary rotation
parent
cb6d4d07
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/data_stores/main/event_push_actions.py
+35
-12
35 additions, 12 deletions
synapse/storage/data_stores/main/event_push_actions.py
with
35 additions
and
12 deletions
synapse/storage/data_stores/main/event_push_actions.py
+
35
−
12
View file @
3cc7f43e
...
@@ -865,7 +865,7 @@ class EventPushActionsStore(EventPushActionsWorkerStore):
...
@@ -865,7 +865,7 @@ class EventPushActionsStore(EventPushActionsWorkerStore):
sql
%
(
"
unread_count
"
,
"
unread_count
"
,
"
unread_count
"
,
""
),
sql
%
(
"
unread_count
"
,
"
unread_count
"
,
"
unread_count
"
,
""
),
(
old_rotate_stream_ordering
,
rotate_to_stream_ordering
),
(
old_rotate_stream_ordering
,
rotate_to_stream_ordering
),
)
)
rows
=
txn
.
fetchall
()
unread_
rows
=
txn
.
fetchall
()
# Then get the count of notifications.
# Then get the count of notifications.
txn
.
execute
(
txn
.
execute
(
...
@@ -874,7 +874,24 @@ class EventPushActionsStore(EventPushActionsWorkerStore):
...
@@ -874,7 +874,24 @@ class EventPushActionsStore(EventPushActionsWorkerStore):
)
)
notif_rows
=
txn
.
fetchall
()
notif_rows
=
txn
.
fetchall
()
logger
.
info
(
"
Rotating notifications, handling %d rows
"
,
len
(
rows
))
# We need to merge both lists into a single object because we might not have the
# same amount of rows in each of them. In this case we use a dict indexed on the
# user ID and room ID to make it easier to populate.
summaries
=
{}
for
row
in
unread_rows
:
summaries
[(
row
[
0
],
row
[
1
])]
=
{
"
unread_count
"
:
row
[
2
],
"
stream_ordering
"
:
row
[
3
],
"
old_user_id
"
:
row
[
4
],
"
notif_count
"
:
0
,
}
# notif_rows is populated based on a subset of the query used to populate
# unread_rows, so we can be sure that there will be no KeyError here.
for
row
in
notif_rows
:
summaries
[(
row
[
0
],
row
[
1
])][
"
notif_count
"
]
=
row
[
2
]
logger
.
info
(
"
Rotating notifications, handling %d rows
"
,
len
(
summaries
))
# If the `old.user_id` above is NULL then we know there isn't already an
# If the `old.user_id` above is NULL then we know there isn't already an
# entry in the table, so we simply insert it. Otherwise we update the
# entry in the table, so we simply insert it. Otherwise we update the
...
@@ -884,14 +901,14 @@ class EventPushActionsStore(EventPushActionsWorkerStore):
...
@@ -884,14 +901,14 @@ class EventPushActionsStore(EventPushActionsWorkerStore):
table
=
"
event_push_summary
"
,
table
=
"
event_push_summary
"
,
values
=
[
values
=
[
{
{
"
user_id
"
:
rows
[
i
]
[
0
],
"
user_id
"
:
key
[
0
],
"
room_id
"
:
rows
[
i
]
[
1
],
"
room_id
"
:
key
[
1
],
"
notif_count
"
:
notif_rows
[
i
][
2
],
"
notif_count
"
:
summary
[
"
notif_count
"
],
"
unread_count
"
:
rows
[
i
][
2
],
"
unread_count
"
:
summary
[
"
unread_count
"
],
"
stream_ordering
"
:
rows
[
i
][
3
],
"
stream_ordering
"
:
summary
[
"
stream_ordering
"
],
}
}
for
i
,
_
in
enumerate
(
rows
)
for
key
,
summary
in
summaries
.
items
(
)
if
rows
[
i
][
4
]
is
None
if
summary
[
"
old_user_id
"
]
is
None
],
],
)
)
...
@@ -902,9 +919,15 @@ class EventPushActionsStore(EventPushActionsWorkerStore):
...
@@ -902,9 +919,15 @@ class EventPushActionsStore(EventPushActionsWorkerStore):
WHERE user_id = ? AND room_id = ?
WHERE user_id = ? AND room_id = ?
"""
,
"""
,
(
(
(
notif_rows
[
i
][
2
],
rows
[
i
][
2
],
rows
[
i
][
3
],
rows
[
i
][
0
],
rows
[
i
][
1
])
(
for
i
,
_
in
enumerate
(
rows
)
summary
[
"
notif_count
"
],
if
rows
[
i
][
4
]
is
not
None
summary
[
"
unread_count
"
],
summary
[
"
stream_ordering
"
],
key
[
0
],
key
[
1
],
)
for
key
,
summary
in
summaries
.
items
()
if
summary
[
"
old_user_id
"
]
is
not
None
),
),
)
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment