Skip to content

Commit 866f96d

Browse files
committed
Refactor cache clearing and implement it
1 parent 21561f3 commit 866f96d

File tree

5 files changed

+72
-19
lines changed

5 files changed

+72
-19
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ignored-argument-names = _.*
8383
max-locals = 15
8484
max-returns = 6
8585
max-branches = 12
86-
max-statements = 50
86+
max-statements = 55
8787
max-parents = 7
8888
max-attributes = 10
8989
min-public-methods = 2

conditional/__init__.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@
2424
from conditional.blueprints.conditional import conditionals_bp
2525
from conditional.blueprints.member_management import member_management_bp
2626
from conditional.blueprints.slideshow import slideshow_bp
27-
28-
from conditional.util.ldap import ldap_get_housing_points
29-
from conditional.util.ldap import ldap_get_active_members
30-
from conditional.util.ldap import ldap_get_intro_members
31-
from conditional.util.ldap import ldap_get_non_alumni_members
32-
from conditional.util.ldap import ldap_get_onfloor_members
33-
from conditional.util.ldap import ldap_get_current_students
34-
from conditional.util.ldap import ldap_get_name
27+
from conditional.blueprints.cache_management import cache_bp
3528

3629
app.register_blueprint(dashboard_bp)
3730
app.register_blueprint(attendance_bp)
@@ -43,6 +36,7 @@
4336
app.register_blueprint(conditionals_bp)
4437
app.register_blueprint(member_management_bp)
4538
app.register_blueprint(slideshow_bp)
39+
app.register_blueprint(cache_bp)
4640

4741
logger.info('conditional started')
4842

@@ -57,15 +51,6 @@ def static_proxy(path):
5751
def default_route():
5852
return redirect('/dashboard')
5953

60-
@app.route('/clearcache')
61-
def clear_cache():
62-
ldap_get_housing_points.cache_clear()
63-
ldap_get_active_members.cache_clear()
64-
ldap_get_intro_members.cache_clear()
65-
ldap_get_non_alumni_members.cache_clear()
66-
ldap_get_onfloor_members.cache_clear()
67-
ldap_get_current_students.cache_clear()
68-
ldap_get_name.cache_clear()
6954

7055
@app.cli.command()
7156
def zoo():
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import structlog
2+
3+
from conditional.util.ldap import ldap_is_eval_director
4+
from conditional.util.ldap import ldap_get_housing_points
5+
from conditional.util.ldap import ldap_get_active_members
6+
from conditional.util.ldap import ldap_get_intro_members
7+
from conditional.util.ldap import ldap_get_non_alumni_members
8+
from conditional.util.ldap import ldap_get_onfloor_members
9+
from conditional.util.ldap import ldap_get_current_students
10+
from conditional.util.ldap import ldap_get_name
11+
12+
from flask import Blueprint, request, redirect
13+
14+
logger = structlog.get_logger()
15+
cache_bp = Blueprint('cache_bp', __name__)
16+
17+
18+
@cache_bp.route('/clearcache')
19+
def clear_cache():
20+
user_name = request.headers.get('x-webauth-user')
21+
22+
if not ldap_is_eval_director(user_name):
23+
return redirect("/dashboard")
24+
25+
logger.info('api', action='purge system cache')
26+
27+
ldap_get_housing_points.cache_clear()
28+
ldap_get_active_members.cache_clear()
29+
ldap_get_intro_members.cache_clear()
30+
ldap_get_non_alumni_members.cache_clear()
31+
ldap_get_onfloor_members.cache_clear()
32+
ldap_get_current_students.cache_clear()
33+
ldap_get_name.cache_clear()
34+
return "cache cleared", 200
35+
36+
37+
def clear_housing_points_cache():
38+
ldap_get_housing_points.cache_clear()
39+
40+
41+
def clear_active_members_cache():
42+
ldap_get_active_members.cache_clear()
43+
44+
45+
def clear_intro_members_cache():
46+
ldap_get_intro_members.cache_clear()
47+
48+
49+
def clear_non_alumni_cache():
50+
ldap_get_non_alumni_members.cache_clear()
51+
52+
53+
def clear_onfloor_members_cache():
54+
ldap_get_onfloor_members.cache_clear()
55+
56+
57+
def clear_current_students_cache():
58+
ldap_get_current_students.cache_clear()
59+
60+
61+
def clear_user_cache(username):
62+
ldap_get_name(username).cache_clear()

conditional/blueprints/dashboard.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ def get_voting_members():
8585
return voting_list
8686

8787

88-
# pylint: disable=too-many-statements
8988
@dashboard_bp.route('/dashboard/')
9089
def display_dashboard():
9190
log = logger.new(user_name=request.headers.get("x-webauth-user"),

conditional/blueprints/member_management.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
from conditional.models.models import OnFloorStatusAssigned
2222
from conditional.models.models import SpringEval
2323

24+
from conditional.blueprints.cache_management import clear_active_members_cache
25+
from conditional.blueprints.cache_management import clear_onfloor_members_cache
26+
2427
from conditional.util.ldap import ldap_is_eval_director
2528
from conditional.util.ldap import ldap_is_financial_director
2629
from conditional.util.ldap import ldap_set_roomnumber
@@ -261,6 +264,7 @@ def member_management_edituser(uid):
261264
{
262265
'active': False
263266
})
267+
clear_active_members_cache()
264268
else:
265269
logger.info('backend', action="edit freshman account %s room: %s onfloor: %s eval_date: %s" %
266270
(uid, post_data['roomNumber'], post_data['onfloorStatus'],
@@ -454,4 +458,7 @@ def member_management_upgrade_user():
454458

455459
db.session.flush()
456460
db.session.commit()
461+
462+
clear_onfloor_members_cache()
463+
457464
return jsonify({"success": True}), 200

0 commit comments

Comments
 (0)