mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 06:03:50 +01:00
Merge pull request #527 from matrix-org/erikj/push_cache
Push: Use storage apis that are cached
This commit is contained in:
commit
f091b73e69
2 changed files with 14 additions and 17 deletions
|
@ -17,7 +17,6 @@ from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.streams.config import PaginationConfig
|
from synapse.streams.config import PaginationConfig
|
||||||
from synapse.types import StreamToken
|
from synapse.types import StreamToken
|
||||||
from synapse.api.constants import Membership
|
|
||||||
|
|
||||||
import synapse.util.async
|
import synapse.util.async
|
||||||
import push_rule_evaluator as push_rule_evaluator
|
import push_rule_evaluator as push_rule_evaluator
|
||||||
|
@ -296,22 +295,19 @@ class Pusher(object):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _get_badge_count(self):
|
def _get_badge_count(self):
|
||||||
room_list = yield self.store.get_rooms_for_user_where_membership_is(
|
invites, joins = yield defer.gatherResults([
|
||||||
user_id=self.user_id,
|
self.store.get_invites_for_user(self.user_id),
|
||||||
membership_list=(Membership.INVITE, Membership.JOIN)
|
self.store.get_rooms_for_user(self.user_id),
|
||||||
)
|
], consumeErrors=True)
|
||||||
|
|
||||||
my_receipts_by_room = yield self.store.get_receipts_for_user(
|
my_receipts_by_room = yield self.store.get_receipts_for_user(
|
||||||
self.user_id,
|
self.user_id,
|
||||||
"m.read",
|
"m.read",
|
||||||
)
|
)
|
||||||
|
|
||||||
badge = 0
|
badge = len(invites)
|
||||||
|
|
||||||
for r in room_list:
|
for r in joins:
|
||||||
if r.membership == Membership.INVITE:
|
|
||||||
badge += 1
|
|
||||||
else:
|
|
||||||
if r.room_id in my_receipts_by_room:
|
if r.room_id in my_receipts_by_room:
|
||||||
last_unread_event_id = my_receipts_by_room[r.room_id]
|
last_unread_event_id = my_receipts_by_room[r.room_id]
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,7 @@ class RoomMemberStore(SQLBaseStore):
|
||||||
membership=membership,
|
membership=membership,
|
||||||
).addCallback(self._get_events)
|
).addCallback(self._get_events)
|
||||||
|
|
||||||
|
@cached()
|
||||||
def get_invites_for_user(self, user_id):
|
def get_invites_for_user(self, user_id):
|
||||||
""" Get all the invite events for a user
|
""" Get all the invite events for a user
|
||||||
Args:
|
Args:
|
||||||
|
|
Loading…
Reference in a new issue