From 144040f126b94f2c1cb04a93ff4cbdd0c6713153 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 11 Aug 2019 15:36:44 +0200 Subject: [PATCH] Compact GridFS at startup --- blueprints/tasks.py | 5 ----- core/activitypub.py | 4 ++++ core/indexes.py | 6 ++++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/blueprints/tasks.py b/blueprints/tasks.py index a521414..ab2d160 100644 --- a/blueprints/tasks.py +++ b/blueprints/tasks.py @@ -289,11 +289,6 @@ def task_cache_actor() -> _Response: # Cache the actor info update_cached_actor(actor) - # TODO(tsileo): Also update following (it's in the object) - # DB.activities.update_many( - # {"meta.object_id": actor.id}, {"$set": {"meta.object": actor.to_dict(embed=True)}} - # ) - app.logger.info(f"actor cached for {iri}") if not activity.has_type([ap.ActivityType.CREATE, ap.ActivityType.ANNOUNCE]): return "" diff --git a/core/activitypub.py b/core/activitypub.py index fbaee28..7f411d2 100644 --- a/core/activitypub.py +++ b/core/activitypub.py @@ -690,4 +690,8 @@ def update_cached_actor(actor: ap.BaseActivity) -> None: } ), ) + # TODO(tsileo): Also update following (it's in the object) + # DB.activities.update_many( + # {"meta.object_id": actor.id}, {"$set": {"meta.object": actor.to_dict(embed=True)}} + # ) _cache_actor_icon(actor) diff --git a/core/indexes.py b/core/indexes.py index d57b006..7cd8865 100644 --- a/core/indexes.py +++ b/core/indexes.py @@ -13,6 +13,12 @@ def create_indexes(): if "activities" in DB.collection_names(): DB.command("compact", "activities") + try: + MEDIA_CACHE.fs._GridFS__database.command("compact", "fs.files") + MEDIA_CACHE.fs._GridFS__database.command("compact", "fs.chunks") + except Exception: + pass + DB.activities.create_index([(_meta(MetaKey.NOTIFICATION), pymongo.ASCENDING)]) DB.activities.create_index( [(_meta(MetaKey.NOTIFICATION_UNREAD), pymongo.ASCENDING)]