Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix the user directory becoming broken (and noisy errors being logged) when knocking and room statistics are in use. #10344

Merged
merged 4 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10344.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the user directory becoming broken (and noisy errors being logged) when knocking and room statistics are in use.
8 changes: 6 additions & 2 deletions synapse/storage/databases/main/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def _upsert_with_additive_relatives_txn(
]

relative_updates = [
"%(field)s = EXCLUDED.%(field)s + %(table)s.%(field)s"
"%(field)s = EXCLUDED.%(field)s + COALESCE(%(table)s.%(field)s, 0)"
% {"table": table, "field": field}
for field in additive_relatives.keys()
]
Expand Down Expand Up @@ -474,7 +474,10 @@ def _upsert_with_additive_relatives_txn(
self.db_pool.simple_insert_txn(txn, table, merged_dict)
else:
for (key, val) in additive_relatives.items():
current_row[key] += val
if current_row[key] is None:
current_row[key] = val
else:
current_row[key] += val
current_row.update(absolutes)
self.db_pool.simple_update_one_txn(txn, table, keyvalues, current_row)

Expand Down Expand Up @@ -604,6 +607,7 @@ def _fetch_current_state_stats(txn):
"invited_members": membership_counts.get(Membership.INVITE, 0),
"left_members": membership_counts.get(Membership.LEAVE, 0),
"banned_members": membership_counts.get(Membership.BAN, 0),
"knocked_members": membership_counts.get(Membership.KNOCK, 0),
"local_users_in_room": len(local_users_in_room),
},
)
Expand Down