Move stuff arround

This commit is contained in:
Thomas Sileo 2019-08-01 21:44:35 +02:00
parent 922c9bebb2
commit cd2ae3d7b0
12 changed files with 112 additions and 121 deletions

20
app.py
View file

@ -38,16 +38,16 @@ import blueprints.well_known
import config
from activitypub import Box
from activitypub import embed_collection
from app_utils import MY_PERSON
from app_utils import _add_answers_to_question
from app_utils import _build_thread
from app_utils import _get_ip
from app_utils import back
from app_utils import csrf
from app_utils import login_required
from app_utils import noindex
from app_utils import paginated_query
from app_utils import post_to_outbox
from core.shared import MY_PERSON
from core.shared import _add_answers_to_question
from core.shared import _build_thread
from core.shared import _get_ip
from core.shared import back
from core.shared import csrf
from core.shared import login_required
from core.shared import noindex
from core.shared import paginated_query
from core.shared import post_to_outbox
from blueprints.api import _api_required
from config import ADMIN_API_KEY
from config import BLACKLIST

View file

@ -20,15 +20,15 @@ from u2flib_server import u2f
import config
from activitypub import Box
from app_utils import MY_PERSON
from app_utils import _build_thread
from app_utils import _Response
from app_utils import csrf
from app_utils import login_required
from app_utils import noindex
from app_utils import p
from app_utils import paginated_query
from app_utils import post_to_outbox
from core.shared import MY_PERSON
from core.shared import _build_thread
from core.shared import _Response
from core.shared import csrf
from core.shared import login_required
from core.shared import noindex
from core.shared import p
from core.shared import paginated_query
from core.shared import post_to_outbox
from config import DB
from config import ID
from config import PASS

View file

@ -26,11 +26,11 @@ from werkzeug.utils import secure_filename
import activitypub
import config
from activitypub import Box
from app_utils import MY_PERSON
from app_utils import _Response
from app_utils import back
from app_utils import csrf
from app_utils import post_to_outbox
from core.shared import MY_PERSON
from core.shared import _Response
from core.shared import back
from core.shared import csrf
from core.shared import post_to_outbox
from config import BASE_URL
from config import DB
from config import DEBUG_MODE

View file

@ -16,8 +16,8 @@ from flask import session
from flask import url_for
from itsdangerous import BadSignature
from app_utils import _get_ip
from app_utils import login_required
from core.shared import _get_ip
from core.shared import login_required
from config import DB
from config import JWT

View file

@ -13,15 +13,15 @@ from little_boxes.errors import NotAnActivityError
from little_boxes.httpsig import HTTPSigAuth
from requests.exceptions import HTTPError
import activity_gc
from core import gc
import activitypub
import config
from activitypub import Box
from app_utils import MY_PERSON
from app_utils import _add_answers_to_question
from app_utils import back
from app_utils import p
from app_utils import post_to_outbox
from core.shared import MY_PERSON
from core.shared import _add_answers_to_question
from core.shared import back
from core.shared import p
from core.shared import post_to_outbox
from config import DB
from core.notifications import set_inbox_flags
from tasks import Tasks
@ -457,7 +457,7 @@ def task_fetch_remote_question():
def task_cleanup():
task = p.parse(flask.request)
app.logger.info(f"task={task!r}")
activity_gc.perform()
gc.perform()
return ""

View file

@ -4,7 +4,6 @@ import subprocess
from datetime import datetime
from enum import Enum
import pymongo
import yaml
from itsdangerous import JSONWebSignatureSerializer
from little_boxes import strtobool
@ -16,8 +15,6 @@ from utils.key import KEY_DIR
from utils.key import get_key
from utils.key import get_secret_key
from utils.media import MediaCache
from utils.meta import MetaKey
from utils.meta import _meta
class ThemeStyle(Enum):
@ -33,16 +30,6 @@ DEFAULT_THEME_PRIMARY_COLOR = {
}
def noop():
pass
CUSTOM_CACHE_HOOKS = False
try:
from cache_hooks import purge as custom_cache_purge_hook
except ModuleNotFoundError:
custom_cache_purge_hook = noop
VERSION = (
subprocess.check_output(["git", "describe", "--always"]).split()[0].decode("utf-8")
)
@ -108,78 +95,6 @@ GRIDFS = mongo_client[f"{DB_NAME}_gridfs"]
MEDIA_CACHE = MediaCache(GRIDFS, USER_AGENT)
def create_indexes():
if "trash" not in DB.collection_names():
DB.create_collection("trash", capped=True, size=50 << 20) # 50 MB
DB.command("compact", "activities")
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)])
DB.activities.create_index([("activity.object.id", pymongo.ASCENDING)])
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)]
)
DB.cache2.create_index(
[
("path", pymongo.ASCENDING),
("type", pymongo.ASCENDING),
("arg", pymongo.ASCENDING),
]
)
DB.cache2.create_index("date", expireAfterSeconds=3600 * 12)
# 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),
]
)
def _drop_db():
if not DEBUG_MODE:
return

76
core/indexes.py Normal file
View file

@ -0,0 +1,76 @@
import pymongo
from config import DB
from utils.meta import _meta
from utils.meta import MetaKey
def create_indexes():
if "trash" not in DB.collection_names():
DB.create_collection("trash", capped=True, size=50 << 20) # 50 MB
DB.command("compact", "activities")
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)])
DB.activities.create_index([("activity.object.id", pymongo.ASCENDING)])
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)]
)
DB.cache2.create_index(
[
("path", pymongo.ASCENDING),
("type", pymongo.ASCENDING),
("arg", pymongo.ASCENDING),
]
)
DB.cache2.create_index("date", expireAfterSeconds=3600 * 12)
# 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),
]
)

View file

@ -7,7 +7,7 @@ services:
ports:
- "27017:27017"
poussetaches:
image: "poussetaches:latest"
image: "poussetaches/poussetaches:latest"
volumes:
- "${DATA_DIR}/poussetaches:/app/poussetaches_data"
environment:

4
run.sh
View file

@ -1,4 +1,4 @@
#!/bin/bash
python -c "import logging; logging.basicConfig(level=logging.DEBUG); import migrations; migrations.perform()"
python -c "import config; config.create_indexes()"
python -c "import logging; logging.basicConfig(level=logging.DEBUG); from core import migrations; migrations.perform()"
python -c "from core import indexes; indexes.create_indexes()"
gunicorn -t 600 -w 5 -b 0.0.0.0:5005 --log-level debug app:app