From 68a4d8ea98a0f9b530464f9b298bbccba281d106 Mon Sep 17 00:00:00 2001 From: Goffi Date: Tue, 14 Apr 2020 20:36:24 +0200 Subject: [PATCH] core (memory/persistent): fixed "items", added "all" + "adel" to LazyPersistentBinaryDict: - `items` was returning the dict with all values, it now returns a Deferred with actual dict items() - `all` new method does return the dict with all values (in a Deferred) - `adel` has been added to LazyPersistentBinaryDict --- sat/memory/persistent.py | 13 ++++++++++++- sat/plugins/plugin_misc_email_invitation.py | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sat/memory/persistent.py b/sat/memory/persistent.py index 67049092..4bd7a844 100644 --- a/sat/memory/persistent.py +++ b/sat/memory/persistent.py @@ -66,7 +66,7 @@ class PersistentDict: return iter(self._cache.items()) def items(self): - return list(self._cache.items()) + return self._cache.items() def __repr__(self): return self._cache.__repr__() @@ -178,6 +178,11 @@ class LazyPersistentBinaryDict(PersistentBinaryDict): raise NotImplementedError def items(self): + d = self.storage.getPrivates(self.namespace, binary=self.binary, profile=self.profile) + d.addCallback(lambda data_dict: data_dict.items()) + return d + + def all(self): return self.storage.getPrivates(self.namespace, binary=self.binary, profile=self.profile) def __repr__(self): @@ -257,6 +262,12 @@ class LazyPersistentBinaryDict(PersistentBinaryDict): return self.storage.setPrivateValue(self.namespace, key, value, self.binary, self.profile) + def adel(self, key): + """Async del, return a Deferred fired when value is actually deleted""" + # XXX: similar as PersistentDict.adel, but doesn't use cache + return self.storage.delPrivateValue( + self.namespace, key, self.binary, self.profile) + def setdefault(self, key, default): raise NotImplementedError diff --git a/sat/plugins/plugin_misc_email_invitation.py b/sat/plugins/plugin_misc_email_invitation.py index 53742fae..4669d4de 100644 --- a/sat/plugins/plugin_misc_email_invitation.py +++ b/sat/plugins/plugin_misc_email_invitation.py @@ -401,7 +401,7 @@ class InvitationsPlugin(object): C.PROF_KEY_NONE: don't filter invitations @return list(unicode): invitations uids """ - invitations = yield self.invitations.items() + invitations = yield self.invitations.all() if profile != C.PROF_KEY_NONE: invitations = {id_:data for id_, data in invitations.items() if data.get('profile') == profile}