mirror of
https://github.com/element-hq/synapse
synced 2024-09-05 09:30:07 +00:00
Merge pull request #537 from matrix-org/erikj/cache_filters
Cache user filters.
This commit is contained in:
commit
f3af1840cb
3 changed files with 11 additions and 4 deletions
|
@ -15,6 +15,8 @@
|
||||||
from synapse.api.errors import SynapseError
|
from synapse.api.errors import SynapseError
|
||||||
from synapse.types import UserID, RoomID
|
from synapse.types import UserID, RoomID
|
||||||
|
|
||||||
|
import ujson as json
|
||||||
|
|
||||||
|
|
||||||
class Filtering(object):
|
class Filtering(object):
|
||||||
|
|
||||||
|
@ -149,6 +151,9 @@ class FilterCollection(object):
|
||||||
"include_leave", False
|
"include_leave", False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<FilterCollection %s>" % (json.dumps(self._filter_json),)
|
||||||
|
|
||||||
def get_filter_json(self):
|
def get_filter_json(self):
|
||||||
return self._filter_json
|
return self._filter_json
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,13 @@
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from ._base import SQLBaseStore
|
from ._base import SQLBaseStore
|
||||||
|
from synapse.util.caches.descriptors import cachedInlineCallbacks
|
||||||
|
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
|
|
||||||
class FilteringStore(SQLBaseStore):
|
class FilteringStore(SQLBaseStore):
|
||||||
@defer.inlineCallbacks
|
@cachedInlineCallbacks(num_args=2)
|
||||||
def get_user_filter(self, user_localpart, filter_id):
|
def get_user_filter(self, user_localpart, filter_id):
|
||||||
def_json = yield self._simple_select_one_onecol(
|
def_json = yield self._simple_select_one_onecol(
|
||||||
table="user_filters",
|
table="user_filters",
|
||||||
|
|
|
@ -382,19 +382,20 @@ class FilteringTestCase(unittest.TestCase):
|
||||||
"types": ["m.*"]
|
"types": ["m.*"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
user = UserID.from_string("@" + user_localpart + ":test")
|
|
||||||
filter_id = yield self.datastore.add_user_filter(
|
filter_id = yield self.datastore.add_user_filter(
|
||||||
user_localpart=user_localpart,
|
user_localpart=user_localpart + "2",
|
||||||
user_filter=user_filter_json,
|
user_filter=user_filter_json,
|
||||||
)
|
)
|
||||||
event = MockEvent(
|
event = MockEvent(
|
||||||
|
event_id="$asdasd:localhost",
|
||||||
sender="@foo:bar",
|
sender="@foo:bar",
|
||||||
type="custom.avatar.3d.crazy",
|
type="custom.avatar.3d.crazy",
|
||||||
)
|
)
|
||||||
events = [event]
|
events = [event]
|
||||||
|
|
||||||
user_filter = yield self.filtering.get_user_filter(
|
user_filter = yield self.filtering.get_user_filter(
|
||||||
user_localpart=user_localpart,
|
user_localpart=user_localpart + "2",
|
||||||
filter_id=filter_id,
|
filter_id=filter_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue