Move logging to __init__ and cache a bit less.

This commit is contained in:
2021-03-07 20:01:48 +01:00
parent 4c60d7f9ea
commit 8d78368db3
3 changed files with 14 additions and 10 deletions
+12 -1
View File
@@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
import bleach import bleach
import logging
import os import os
from flask import Flask from flask import Flask
from flask_caching import Cache from flask_caching import Cache
@@ -22,6 +23,11 @@ from . import util
from flask_cors import CORS from flask_cors import CORS
cache = Cache() cache = Cache()
logging.basicConfig(
filename='agora.log',
level=logging.WARNING,
format='%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s'
)
# what is this doing here, I have no idea. # what is this doing here, I have no idea.
# todo: move to util. # todo: move to util.
@@ -39,7 +45,12 @@ def create_app(test_config=None):
CORS(app) CORS(app)
cache.init_app(app, config={ cache.init_app(app, config={
'CACHE_TYPE': 'SimpleCache', 'CACHE_TYPE': 'SimpleCache',
'CACHE_DEFAULT_TIMEOUT': 30, 'CACHE_DEFAULT_TIMEOUT': 60,
#'CACHE_TYPE': 'FileSystemCache',
#'CACHE_DIR': '/tmp',
#'CACHE_TYPE': 'MemcachedCache',
#'CACHE_THRESHOLD': 10,
#'CACHE_MEMCACHED_SERVERS': 'localhost',
#'CACHE_KEY_PREFIX': 'agora', #'CACHE_KEY_PREFIX': 'agora',
#'CACHE_REDIS_HOST': 'localhost', #'CACHE_REDIS_HOST': 'localhost',
}) })
-7
View File
@@ -13,7 +13,6 @@
# limitations under the License. # limitations under the License.
import datetime import datetime
import logging
import jsons import jsons
from flask import Blueprint, url_for, render_template, current_app, Response, redirect, request, jsonify from flask import Blueprint, url_for, render_template, current_app, Response, redirect, request, jsonify
from markupsafe import escape from markupsafe import escape
@@ -27,12 +26,6 @@ from . import util
bp = Blueprint('agora', __name__) bp = Blueprint('agora', __name__)
G = db.G G = db.G
logging.basicConfig(
filename='agora.log',
level=logging.WARNING,
format='%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s'
)
# Special # Special
@bp.route('/index') @bp.route('/index')
@bp.route('/') @bp.route('/')
+2 -2
View File
@@ -112,7 +112,7 @@ class Graph:
# Running something like this would be ideal eventually though. # Running something like this would be ideal eventually though.
# It might also work better once all pulling/pushing logic moves to Graph, where it belongs, # It might also work better once all pulling/pushing logic moves to Graph, where it belongs,
# and can make use of more sensible algorithms. # and can make use of more sensible algorithms.
@cache.memoize(timeout=30) # @cache.memoize(timeout=30)
def compute_transclusion(self, include_journals=True): def compute_transclusion(self, include_journals=True):
# Add artisanal virtual subnodes (resulting from transclusion/[[push]]) to all nodes. # Add artisanal virtual subnodes (resulting from transclusion/[[push]]) to all nodes.
@@ -121,7 +121,7 @@ class Graph:
node.subnodes.extend(pushed_subnodes) node.subnodes.extend(pushed_subnodes)
# does this belong here? # does this belong here?
@cache.memoize(timeout=30) # @cache.memoize(timeout=30)
def subnodes(self, sort=lambda x: x.uri.lower()): def subnodes(self, sort=lambda x: x.uri.lower()):
# Markdown. # Markdown.
subnodes = [Subnode(f) for f in glob.glob(os.path.join(config.AGORA_PATH, '**/*.md'), recursive=True)] subnodes = [Subnode(f) for f in glob.glob(os.path.join(config.AGORA_PATH, '**/*.md'), recursive=True)]