forked from rDrama/rDrama
don't cache user objects in redis
parent
6ab9f2324c
commit
7da9a224e9
|
@ -17,7 +17,7 @@ from files.helpers.settings import get_settings, toggle_setting
|
||||||
from files.helpers.useractions import *
|
from files.helpers.useractions import *
|
||||||
from files.routes.routehelpers import check_for_alts
|
from files.routes.routehelpers import check_for_alts
|
||||||
from files.routes.wrappers import *
|
from files.routes.wrappers import *
|
||||||
from files.routes.routehelpers import get_alt_graph
|
from files.routes.routehelpers import get_alt_graph, get_alt_graph_ids
|
||||||
|
|
||||||
from .front import frontlist
|
from .front import frontlist
|
||||||
|
|
||||||
|
@ -699,8 +699,8 @@ def admin_add_alt(v:User, username):
|
||||||
g.db.add(a)
|
g.db.add(a)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
|
|
||||||
cache.delete_memoized(get_alt_graph, user1.id)
|
cache.delete_memoized(get_alt_graph_ids, user1.id)
|
||||||
cache.delete_memoized(get_alt_graph, user2.id)
|
cache.delete_memoized(get_alt_graph_ids, user2.id)
|
||||||
|
|
||||||
check_for_alts(user1, include_current_session=False)
|
check_for_alts(user1, include_current_session=False)
|
||||||
check_for_alts(user2, include_current_session=False)
|
check_for_alts(user2, include_current_session=False)
|
||||||
|
|
|
@ -30,7 +30,7 @@ def validate_formkey(u:User, formkey:Optional[str]) -> bool:
|
||||||
return validate_hash(get_raw_formkey(u), formkey)
|
return validate_hash(get_raw_formkey(u), formkey)
|
||||||
|
|
||||||
@cache.memoize(timeout=604800)
|
@cache.memoize(timeout=604800)
|
||||||
def get_alt_graph(uid:int) -> List[User]:
|
def get_alt_graph_ids(uid:int) -> List[int]:
|
||||||
alt_graph_cte = g.db.query(literal(uid).label('user_id')).select_from(Alt).cte('alt_graph', recursive=True)
|
alt_graph_cte = g.db.query(literal(uid).label('user_id')).select_from(Alt).cte('alt_graph', recursive=True)
|
||||||
|
|
||||||
alt_graph_cte_inner = g.db.query(
|
alt_graph_cte_inner = g.db.query(
|
||||||
|
@ -43,7 +43,11 @@ def get_alt_graph(uid:int) -> List[User]:
|
||||||
)
|
)
|
||||||
|
|
||||||
alt_graph_cte = alt_graph_cte.union(alt_graph_cte_inner)
|
alt_graph_cte = alt_graph_cte.union(alt_graph_cte_inner)
|
||||||
return g.db.query(User).filter(User.id == alt_graph_cte.c.user_id, User.id != uid).order_by(User.username).all()
|
return set([x[0] for x in g.db.query(User.id).filter(User.id == alt_graph_cte.c.user_id, User.id != uid).all()])
|
||||||
|
|
||||||
|
def get_alt_graph(uid:int) -> List[User]:
|
||||||
|
alt_ids = get_alt_graph_ids(uid)
|
||||||
|
return g.db.query(User).filter(User.id.in_(alt_ids)).order_by(User.username)
|
||||||
|
|
||||||
def add_alt(user1:int, user2:int):
|
def add_alt(user1:int, user2:int):
|
||||||
li = [user1, user2]
|
li = [user1, user2]
|
||||||
|
@ -52,8 +56,8 @@ def add_alt(user1:int, user2:int):
|
||||||
new_alt = Alt(user1=user1, user2=user2)
|
new_alt = Alt(user1=user1, user2=user2)
|
||||||
g.db.add(new_alt)
|
g.db.add(new_alt)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
cache.delete_memoized(get_alt_graph, user1)
|
cache.delete_memoized(get_alt_graph_ids, user1)
|
||||||
cache.delete_memoized(get_alt_graph, user2)
|
cache.delete_memoized(get_alt_graph_ids, user2)
|
||||||
|
|
||||||
def check_for_alts(current:User, include_current_session=True):
|
def check_for_alts(current:User, include_current_session=True):
|
||||||
current_id = current.id
|
current_id = current.id
|
||||||
|
|
Loading…
Reference in New Issue