Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure frozen state on database and cache are in sync on !map #534

Merged
merged 6 commits into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,14 @@ async def _map(ctx: Context) -> str | None:

async with app.state.services.database.connection() as db_conn:
if ctx.args[1] == "set":
# update whole set
await db_conn.execute(
"UPDATE maps SET status = :status, frozen = 1 WHERE set_id = :set_id",
{"status": new_status, "set_id": bmap.set_id},
)
# update all maps in the set
for _bmap in bmap.set.maps:
await maps_repo.update(_bmap.id, status=new_status, frozen=True)

# make sure cache and db are synced about the newest change
for _bmap in app.state.cache.beatmapset[bmap.set_id].maps:
_bmap.status = new_status
_bmap.frozen = True

# select all map ids for clearing map requests.
map_ids = [
Expand All @@ -661,17 +664,16 @@ async def _map(ctx: Context) -> str | None:
)
]

for bmap in app.state.cache.beatmapset[bmap.set_id].maps:
bmap.status = new_status

else:
# update only map
await maps_repo.update(bmap.id, status=new_status, frozen=True)

map_ids = [bmap.id]

# make sure cache and db are synced about the newest change
if bmap.md5 in app.state.cache.beatmap:
app.state.cache.beatmap[bmap.md5].status = new_status
app.state.cache.beatmap[bmap.md5].frozen = True
cmyui marked this conversation as resolved.
Show resolved Hide resolved

map_ids = [bmap.id]

# deactivate rank requests for all ids
await db_conn.execute(
Expand Down