From 269c5135c21c03600a177bdef4a9ff8beef0eb1f Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 1 Sep 2018 11:17:46 +0200 Subject: [PATCH] Start working on indexes --- Dockerfile | 1 + config.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Dockerfile b/Dockerfile index 8202116..e813f1c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,4 +3,5 @@ ADD . /app WORKDIR /app RUN pip install -r requirements.txt ENV FLASK_APP=app.py +RUN python -c "import config; config.create_indexes()" CMD ["gunicorn", "-t", "300", "-w", "2", "-b", "0.0.0.0:5005", "--log-level", "debug", "app:app"] diff --git a/config.py b/config.py index 58b4974..f6af26d 100644 --- a/config.py +++ b/config.py @@ -11,6 +11,7 @@ from itsdangerous import JSONWebSignatureSerializer from little_boxes import strtobool from little_boxes.activitypub import DEFAULT_CTX from pymongo import MongoClient +import pymongo from utils.key import KEY_DIR from utils.key import get_key @@ -101,6 +102,38 @@ GRIDFS = mongo_client[f"{DB_NAME}_gridfs"] MEDIA_CACHE = MediaCache(GRIDFS, USER_AGENT) +def create_indexes(): + DB.activities.create_index([("remote_id", pymongo.ASCENDING)]) + + # Index for the block query + DB.activities.create_index( + [ + ("box", pymongo.ASCENDING), + ("type", pymongo.ASCENDING), + ("meta.undo", pymongo.ASCENDING), + ] + ) + + # Index for count queries + DB.activities.create_index( + [ + ("box", pymongo.ASCENDING), + ("type", pymongo.ASCENDING), + ("meta.undo", pymongo.ASCENDING), + ("meta.deleted", pymongo.ASCENDING), + ] + ) + + DB.activities.create_index( + [ + ("type", pymongo.ASCENDING), + ("activity.object.type", pymongo.ASCENDING), + ("activity.object.inReplyTo", pymongo.ASCENDING), + ("meta.deleted", pymongo.ASCENDING), + ] + ) + + def _drop_db(): if not DEBUG_MODE: return