mirror of https://gitlab.com/litecord/litecord.git
pubsub.lazy_guild: add cleanup of member lists
- blueprints.channel: delete member list when deleting channel
This commit is contained in:
parent
915b6224e9
commit
d1ef08fbd0
|
|
@ -185,6 +185,10 @@ async def close_channel(channel_id):
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
""", channel_id)
|
""", channel_id)
|
||||||
|
|
||||||
|
# clean its member list representation
|
||||||
|
lazy_guilds = app.dispatcher.backends['lazy_guild']
|
||||||
|
lazy_guilds.remove_channel(channel_id)
|
||||||
|
|
||||||
await app.dispatcher.dispatch_guild(
|
await app.dispatcher.dispatch_guild(
|
||||||
guild_id, 'CHANNEL_DELETE', chan)
|
guild_id, 'CHANNEL_DELETE', chan)
|
||||||
return jsonify(chan)
|
return jsonify(chan)
|
||||||
|
|
@ -404,6 +408,8 @@ async def update_channel(channel_id):
|
||||||
await update_handler(channel_id, j)
|
await update_handler(channel_id, j)
|
||||||
|
|
||||||
chan = await app.storage.get_channel(channel_id)
|
chan = await app.storage.get_channel(channel_id)
|
||||||
|
|
||||||
|
|
||||||
await app.dispatcher.dispatch('guild', guild_id, 'CHANNEL_UPDATE', chan)
|
await app.dispatcher.dispatch('guild', guild_id, 'CHANNEL_UPDATE', chan)
|
||||||
return jsonify(chan)
|
return jsonify(chan)
|
||||||
|
|
||||||
|
|
@ -498,6 +504,7 @@ async def _search_channel(channel_id):
|
||||||
user_id = await token_check()
|
user_id = await token_check()
|
||||||
await channel_check(user_id, channel_id)
|
await channel_check(user_id, channel_id)
|
||||||
await channel_perm_check(user_id, channel_id, 'read_messages')
|
await channel_perm_check(user_id, channel_id, 'read_messages')
|
||||||
|
|
||||||
j = validate(request.args, SEARCH_CHANNEL)
|
j = validate(request.args, SEARCH_CHANNEL)
|
||||||
|
|
||||||
# main message ids
|
# main message ids
|
||||||
|
|
|
||||||
|
|
@ -1264,6 +1264,17 @@ class GuildMemberList:
|
||||||
|
|
||||||
return await self.resync(sess_ids_resync, role_item_index)
|
return await self.resync(sess_ids_resync, role_item_index)
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
"""Remove data."""
|
||||||
|
log.info('closing GML gid={} cid={}, {} subscribers',
|
||||||
|
self.guild_id, self.channel_id, len(self.state))
|
||||||
|
|
||||||
|
self.guild_id = None
|
||||||
|
self.channel_id = None
|
||||||
|
self.main = None
|
||||||
|
self.list = MemberList
|
||||||
|
self.state = {}
|
||||||
|
|
||||||
|
|
||||||
class LazyGuildDispatcher(Dispatcher):
|
class LazyGuildDispatcher(Dispatcher):
|
||||||
"""Main class holding the member lists for lazy guilds."""
|
"""Main class holding the member lists for lazy guilds."""
|
||||||
|
|
@ -1327,6 +1338,19 @@ class LazyGuildDispatcher(Dispatcher):
|
||||||
|
|
||||||
await handler(guild_id, *args, **kwargs)
|
await handler(guild_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def remove_channel(self, channel_id: int):
|
||||||
|
"""Remove a channel from the manager."""
|
||||||
|
try:
|
||||||
|
gml = self.state.pop(channel_id)
|
||||||
|
gml.close()
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def chan_update(self, channel_id: int):
|
||||||
|
"""Signal a channel update to a member list."""
|
||||||
|
gml = await self.get_gml(channel_id)
|
||||||
|
await gml.chan_update()
|
||||||
|
|
||||||
async def _call_all_lists(self, guild_id, method_str: str, *args):
|
async def _call_all_lists(self, guild_id, method_str: str, *args):
|
||||||
lists = self.get_gml_guild(guild_id)
|
lists = self.get_gml_guild(guild_id)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue