2019-08-01 14:44:35 -05:00
|
|
|
import pymongo
|
2019-08-01 15:00:26 -05:00
|
|
|
|
2019-08-01 14:44:35 -05:00
|
|
|
from config import DB
|
2019-08-11 06:56:18 -05:00
|
|
|
from config import MEDIA_CACHE
|
2019-08-01 15:00:26 -05:00
|
|
|
from core.meta import MetaKey
|
|
|
|
from core.meta import _meta
|
2019-08-01 14:44:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
def create_indexes():
|
|
|
|
if "trash" not in DB.collection_names():
|
|
|
|
DB.create_collection("trash", capped=True, size=50 << 20) # 50 MB
|
|
|
|
|
2019-08-04 13:08:47 -05:00
|
|
|
if "activities" in DB.collection_names():
|
|
|
|
DB.command("compact", "activities")
|
|
|
|
|
2019-08-11 08:36:44 -05:00
|
|
|
try:
|
|
|
|
MEDIA_CACHE.fs._GridFS__database.command("compact", "fs.files")
|
|
|
|
MEDIA_CACHE.fs._GridFS__database.command("compact", "fs.chunks")
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
2019-08-01 14:44:35 -05:00
|
|
|
DB.activities.create_index([(_meta(MetaKey.NOTIFICATION), pymongo.ASCENDING)])
|
|
|
|
DB.activities.create_index(
|
|
|
|
[(_meta(MetaKey.NOTIFICATION_UNREAD), pymongo.ASCENDING)]
|
|
|
|
)
|
|
|
|
DB.activities.create_index([("remote_id", pymongo.ASCENDING)])
|
2019-08-04 13:08:47 -05:00
|
|
|
DB.activities.create_index([("meta.actor_id", pymongo.ASCENDING)])
|
|
|
|
DB.activities.create_index([("meta.object_id", pymongo.ASCENDING)])
|
2019-08-01 14:44:35 -05:00
|
|
|
DB.activities.create_index([("meta.thread_root_parent", pymongo.ASCENDING)])
|
|
|
|
DB.activities.create_index(
|
|
|
|
[
|
|
|
|
("meta.thread_root_parent", pymongo.ASCENDING),
|
|
|
|
("meta.deleted", pymongo.ASCENDING),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
DB.activities.create_index(
|
|
|
|
[("activity.object.id", pymongo.ASCENDING), ("meta.deleted", pymongo.ASCENDING)]
|
|
|
|
)
|
2019-08-04 13:08:47 -05:00
|
|
|
DB.activities.create_index(
|
|
|
|
[("meta.object_id", pymongo.ASCENDING), ("type", pymongo.ASCENDING)]
|
2019-08-01 14:44:35 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
# 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([("box", pymongo.ASCENDING)])
|
|
|
|
|
|
|
|
# Outbox query
|
|
|
|
DB.activities.create_index(
|
|
|
|
[
|
|
|
|
("box", pymongo.ASCENDING),
|
|
|
|
("type", pymongo.ASCENDING),
|
|
|
|
("meta.undo", pymongo.ASCENDING),
|
|
|
|
("meta.deleted", pymongo.ASCENDING),
|
|
|
|
("meta.public", pymongo.ASCENDING),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
DB.activities.create_index(
|
|
|
|
[
|
|
|
|
("type", pymongo.ASCENDING),
|
|
|
|
("activity.object.type", pymongo.ASCENDING),
|
|
|
|
("activity.object.inReplyTo", pymongo.ASCENDING),
|
|
|
|
("meta.deleted", pymongo.ASCENDING),
|
|
|
|
]
|
|
|
|
)
|
2019-08-11 06:56:18 -05:00
|
|
|
|
|
|
|
# For the is_actor_icon_cached query
|
|
|
|
MEDIA_CACHE.fs._GridFS__files.create_index([("url", 1), ("kind", 1)])
|
2019-08-18 03:53:52 -05:00
|
|
|
|
|
|
|
# Replies index
|
|
|
|
DB.replies.create_index([("remote_id", pymongo.ASCENDING)])
|
|
|
|
DB.replies.create_index([("meta.thread_root_parent", pymongo.ASCENDING)])
|
|
|
|
DB.replies.create_index(
|
|
|
|
[
|
|
|
|
("meta.thread_root_parent", pymongo.ASCENDING),
|
|
|
|
("meta.deleted", pymongo.ASCENDING),
|
|
|
|
]
|
|
|
|
)
|