remove app kwargs from delete_user and mass_user_update

- manage.cmd.users: don't send updates when deleting users

the rationale for this is that while we have an app.dispatcher, it is
fully empty since we created a mock just for manage.py operations. to
have proper side-effects occouring on the actual main app, we'd need to
implement some kind of IPC, and i'm not up for that task, yet.
This commit is contained in:
Luna 2019-10-25 08:47:04 -03:00
parent 78b45b022a
commit f54c002a31
2 changed files with 15 additions and 19 deletions

View File

@ -41,40 +41,37 @@ bp = Blueprint("user", __name__)
log = Logger(__name__)
async def mass_user_update(user_id, app_=None):
async def mass_user_update(user_id):
"""Dispatch USER_UPDATE in a mass way."""
if app_ is None:
app_ = app
# by using dispatch_with_filter
# we're guaranteeing all shards will get
# a USER_UPDATE once and not any others.
session_ids = []
public_user = await app_.storage.get_user(user_id)
private_user = await app_.storage.get_user(user_id, secure=True)
public_user = await app.storage.get_user(user_id)
private_user = await app.storage.get_user(user_id, secure=True)
session_ids.extend(
await app_.dispatcher.dispatch_user(user_id, "USER_UPDATE", private_user)
await app.dispatcher.dispatch_user(user_id, "USER_UPDATE", private_user)
)
guild_ids = await app_.user_storage.get_user_guilds(user_id)
friend_ids = await app_.user_storage.get_friend_ids(user_id)
guild_ids = await app.user_storage.get_user_guilds(user_id)
friend_ids = await app.user_storage.get_friend_ids(user_id)
session_ids.extend(
await app_.dispatcher.dispatch_many_filter_list(
await app.dispatcher.dispatch_many_filter_list(
"guild", guild_ids, session_ids, "USER_UPDATE", public_user
)
)
session_ids.extend(
await app_.dispatcher.dispatch_many_filter_list(
await app.dispatcher.dispatch_many_filter_list(
"friend", friend_ids, session_ids, "USER_UPDATE", public_user
)
)
await app_.dispatcher.dispatch_many("lazy_guild", guild_ids, "update_user", user_id)
await app.dispatcher.dispatch_many("lazy_guild", guild_ids, "update_user", user_id)
return public_user, private_user
@ -495,12 +492,9 @@ async def _del_from_table(db, table: str, user_id: int):
log.info("Deleting uid {} from {}, res: {!r}", user_id, table, res)
async def delete_user(user_id, *, app_=None):
async def delete_user(user_id, *, mass_update: bool = True):
"""Delete a user. Does not disconnect the user."""
if app_ is None:
app_ = app
db = app_.db
db = app.db
new_username = f"Deleted User {rand_hex()}"
@ -559,7 +553,8 @@ async def delete_user(user_id, *, app_=None):
# after updating the user, we send USER_UPDATE so that all the other
# clients can refresh their caches on the now-deleted user
await mass_user_update(user_id, app_=app_)
if mass_update:
await mass_user_update(user_id)
async def user_disconnect(user_id: int):

View File

@ -129,7 +129,8 @@ async def del_user(ctx, args):
print("not confirmed")
return
await delete_user(uid, app_=ctx)
# we don't have pubsub context in the manage process to send update events
await delete_user(uid, mass_update=False)
print("ok")