Don't keep around old stream IDs forever

This commit is contained in:
Erik Johnston 2017-03-03 16:02:53 +00:00
parent 9834367eea
commit f2581ee8b8

View file

@ -16,6 +16,7 @@ from synapse.api import errors
from synapse.api.constants import EventTypes from synapse.api.constants import EventTypes
from synapse.util import stringutils from synapse.util import stringutils
from synapse.util.async import Linearizer from synapse.util.async import Linearizer
from synapse.util.caches.expiringcache import ExpiringCache
from synapse.util.metrics import measure_func from synapse.util.metrics import measure_func
from synapse.types import get_domain_from_id, RoomStreamToken from synapse.types import get_domain_from_id, RoomStreamToken
from twisted.internet import defer from twisted.internet import defer
@ -344,7 +345,13 @@ class DeviceListEduUpdater(object):
# Recently seen stream ids. We don't bother keeping these in the DB, # Recently seen stream ids. We don't bother keeping these in the DB,
# but they're useful to have them about to reduce the number of spurious # but they're useful to have them about to reduce the number of spurious
# resyncs. # resyncs.
self._seen_updates = {} self._seen_updates = ExpiringCache(
cache_name="device_update_edu",
clock=self.clock,
max_len=10000,
expiry_ms=30 * 60 * 1000,
iterable=True,
)
@defer.inlineCallbacks @defer.inlineCallbacks
def incoming_device_list_update(self, origin, edu_content): def incoming_device_list_update(self, origin, edu_content):
@ -412,7 +419,7 @@ class DeviceListEduUpdater(object):
) )
self._seen_updates.setdefault(user_id, set()).update( self._seen_updates.setdefault(user_id, set()).update(
[stream_id for _, stream_id, _, _ in pending_updates] stream_id for _, stream_id, _, _ in pending_updates
) )
@defer.inlineCallbacks @defer.inlineCallbacks