mirror of
https://github.com/element-hq/synapse
synced 2024-09-01 21:30:21 +00:00
Allow ratelimiting on workers
This commit is contained in:
parent
495cb100d1
commit
cd9765805e
1 changed files with 29 additions and 29 deletions
|
@ -170,6 +170,35 @@ class RoomWorkerStore(SQLBaseStore):
|
||||||
desc="is_room_blocked",
|
desc="is_room_blocked",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@cachedInlineCallbacks(max_entries=10000)
|
||||||
|
def get_ratelimit_for_user(self, user_id):
|
||||||
|
"""Check if there are any overrides for ratelimiting for the given
|
||||||
|
user
|
||||||
|
|
||||||
|
Args:
|
||||||
|
user_id (str)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
RatelimitOverride if there is an override, else None. If the contents
|
||||||
|
of RatelimitOverride are None or 0 then ratelimitng has been
|
||||||
|
disabled for that user entirely.
|
||||||
|
"""
|
||||||
|
row = yield self._simple_select_one(
|
||||||
|
table="ratelimit_override",
|
||||||
|
keyvalues={"user_id": user_id},
|
||||||
|
retcols=("messages_per_second", "burst_count"),
|
||||||
|
allow_none=True,
|
||||||
|
desc="get_ratelimit_for_user",
|
||||||
|
)
|
||||||
|
|
||||||
|
if row:
|
||||||
|
defer.returnValue(RatelimitOverride(
|
||||||
|
messages_per_second=row["messages_per_second"],
|
||||||
|
burst_count=row["burst_count"],
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
defer.returnValue(None)
|
||||||
|
|
||||||
|
|
||||||
class RoomStore(RoomWorkerStore, SearchStore):
|
class RoomStore(RoomWorkerStore, SearchStore):
|
||||||
|
|
||||||
|
@ -469,35 +498,6 @@ class RoomStore(RoomWorkerStore, SearchStore):
|
||||||
"get_all_new_public_rooms", get_all_new_public_rooms
|
"get_all_new_public_rooms", get_all_new_public_rooms
|
||||||
)
|
)
|
||||||
|
|
||||||
@cachedInlineCallbacks(max_entries=10000)
|
|
||||||
def get_ratelimit_for_user(self, user_id):
|
|
||||||
"""Check if there are any overrides for ratelimiting for the given
|
|
||||||
user
|
|
||||||
|
|
||||||
Args:
|
|
||||||
user_id (str)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
RatelimitOverride if there is an override, else None. If the contents
|
|
||||||
of RatelimitOverride are None or 0 then ratelimitng has been
|
|
||||||
disabled for that user entirely.
|
|
||||||
"""
|
|
||||||
row = yield self._simple_select_one(
|
|
||||||
table="ratelimit_override",
|
|
||||||
keyvalues={"user_id": user_id},
|
|
||||||
retcols=("messages_per_second", "burst_count"),
|
|
||||||
allow_none=True,
|
|
||||||
desc="get_ratelimit_for_user",
|
|
||||||
)
|
|
||||||
|
|
||||||
if row:
|
|
||||||
defer.returnValue(RatelimitOverride(
|
|
||||||
messages_per_second=row["messages_per_second"],
|
|
||||||
burst_count=row["burst_count"],
|
|
||||||
))
|
|
||||||
else:
|
|
||||||
defer.returnValue(None)
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def block_room(self, room_id, user_id):
|
def block_room(self, room_id, user_id):
|
||||||
yield self._simple_insert(
|
yield self._simple_insert(
|
||||||
|
|
Loading…
Reference in a new issue