Version 0.1.1 rise to flask app factory
This commit is contained in:
26
Html/apps/services/memory_service.py
Normal file
26
Html/apps/services/memory_service.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# myapp/services/memory_service.py
|
||||
import os, json
|
||||
from flask import current_app
|
||||
from db.user import load_user_from_json # 按你项目实际替换
|
||||
|
||||
def save_chapter_memory_by_uuid(
|
||||
user_uuid: str,
|
||||
course_id: str,
|
||||
lesson_id: str,
|
||||
subchapter_title: str,
|
||||
mem_list,
|
||||
score,
|
||||
is_rebuttal: bool,
|
||||
):
|
||||
uuid2username = current_app.extensions["uuid2username"]
|
||||
user_map = current_app.extensions["user_id2UserClass"] # 可复用缓存
|
||||
user_data_dir = current_app.config["USER_DATA_DIR"]
|
||||
|
||||
username = uuid2username[user_uuid]
|
||||
# 若内存里已有用户对象就直接用;否则从 JSON 载入
|
||||
user_obj = user_map.get(user_uuid) or load_user_from_json(username, user_data_dir=user_data_dir)
|
||||
user_map[user_uuid] = user_obj
|
||||
|
||||
user_obj.save_chapter_memory(
|
||||
course_id, lesson_id, subchapter_title, mem_list, score, is_rebuttal
|
||||
)
|
||||
Reference in New Issue
Block a user