Start working on indexes

This commit is contained in:
Thomas Sileo 2018-09-01 11:17:46 +02:00
parent 2464dd8782
commit 269c5135c2
2 changed files with 34 additions and 0 deletions

View file

@ -3,4 +3,5 @@ ADD . /app
WORKDIR /app WORKDIR /app
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
ENV FLASK_APP=app.py 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"] CMD ["gunicorn", "-t", "300", "-w", "2", "-b", "0.0.0.0:5005", "--log-level", "debug", "app:app"]

View file

@ -11,6 +11,7 @@ from itsdangerous import JSONWebSignatureSerializer
from little_boxes import strtobool from little_boxes import strtobool
from little_boxes.activitypub import DEFAULT_CTX from little_boxes.activitypub import DEFAULT_CTX
from pymongo import MongoClient from pymongo import MongoClient
import pymongo
from utils.key import KEY_DIR from utils.key import KEY_DIR
from utils.key import get_key from utils.key import get_key
@ -101,6 +102,38 @@ GRIDFS = mongo_client[f"{DB_NAME}_gridfs"]
MEDIA_CACHE = MediaCache(GRIDFS, USER_AGENT) 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(): def _drop_db():
if not DEBUG_MODE: if not DEBUG_MODE:
return return