WebHost: Add deletion of old content to cleanup function (#6119)

---------

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
This commit is contained in:
Fabian Dill
2026-05-01 22:38:46 +02:00
committed by GitHub
parent 234b0581c9
commit a68109f5a7
4 changed files with 122 additions and 3 deletions
+2
View File
@@ -48,6 +48,8 @@ app.config["JOB_THRESHOLD"] = 1
app.config["JOB_TIME"] = 600
# maximum time in seconds since last activity for a room to be hosted
app.config["MAX_ROOM_TIMEOUT"] = 259200
# minimum time in days since last activity for a room to be deleted. 0 to disable.
app.config["ROOM_AUTO_DELETE"] = 0
# memory limit for generator processes in bytes
app.config["GENERATOR_MEMORY_LIMIT"] = 4294967296
+8 -3
View File
@@ -100,13 +100,18 @@ def init_generator(config: dict[str, Any]) -> None:
db.generate_mapping()
def cleanup():
"""delete unowned user-content"""
def cleanup(config: dict[str, Any]):
"""delete unowned or old user-content"""
auto_delete: int = config.get("ROOM_AUTO_DELETE", 0)
with db_session:
# >>> bool(uuid.UUID(int=0))
# True
rooms = Room.select(lambda room: room.owner == UUID(int=0)).delete(bulk=True)
seeds = Seed.select(lambda seed: seed.owner == UUID(int=0) and not seed.rooms).delete(bulk=True)
if auto_delete > 0:
cutoff = utcnow() - timedelta(days=auto_delete)
rooms += Room.select(lambda room: room.last_activity < cutoff).delete(bulk=True)
seeds += Seed.select(lambda seed: not seed.rooms and seed.creation_time < cutoff).delete(bulk=True)
slots = Slot.select(lambda slot: not slot.seed).delete(bulk=True)
# Command gets deleted by ponyorm Cascade Delete, as Room is Required
if rooms or seeds or slots:
@@ -118,7 +123,7 @@ def autohost(config: dict):
stop_event = _stop_event
try:
with Locker("autohost"):
cleanup()
cleanup(config)
hosters = []
for x in range(config["HOSTERS"]):
hoster = MultiworldInstance(config, x)