mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
perf: Memory optimization
This commit is contained in:
parent
85f2e9e4a0
commit
c44554f4d4
|
|
@ -258,23 +258,24 @@ class ChatInfo:
|
|||
@staticmethod
|
||||
def map_to_chat_record(chat_record_dict):
|
||||
return ChatRecord(id=chat_record_dict.get('id'),
|
||||
chat_id=chat_record_dict.get('chat_id'),
|
||||
vote_status=chat_record_dict.get('vote_status'),
|
||||
problem_text=chat_record_dict.get('problem_text'),
|
||||
answer_text=chat_record_dict.get('answer_text'),
|
||||
answer_text_list=chat_record_dict.get('answer_text_list'),
|
||||
message_tokens=chat_record_dict.get('message_tokens'),
|
||||
answer_tokens=chat_record_dict.get('answer_tokens'),
|
||||
const=chat_record_dict.get('const'),
|
||||
details=chat_record_dict.get('details'),
|
||||
improve_paragraph_id_list=chat_record_dict.get('improve_paragraph_id_list'),
|
||||
run_time=chat_record_dict.get('run_time'),
|
||||
index=chat_record_dict.get('index'), )
|
||||
chat_id=chat_record_dict.get('chat_id'),
|
||||
vote_status=chat_record_dict.get('vote_status'),
|
||||
problem_text=chat_record_dict.get('problem_text'),
|
||||
answer_text=chat_record_dict.get('answer_text'),
|
||||
answer_text_list=chat_record_dict.get('answer_text_list'),
|
||||
message_tokens=chat_record_dict.get('message_tokens'),
|
||||
answer_tokens=chat_record_dict.get('answer_tokens'),
|
||||
const=chat_record_dict.get('const'),
|
||||
details=chat_record_dict.get('details'),
|
||||
improve_paragraph_id_list=chat_record_dict.get('improve_paragraph_id_list'),
|
||||
run_time=chat_record_dict.get('run_time'),
|
||||
index=chat_record_dict.get('index'), )
|
||||
|
||||
def set_cache(self):
|
||||
cache.set(Cache_Version.CHAT.get_key(key=self.chat_id),json.dumps( self.to_dict(),cls=SystemEncoder),
|
||||
version=Cache_Version.CHAT_INFO.get_version(),
|
||||
timeout=60 * 30)
|
||||
if self.debug:
|
||||
cache.set(Cache_Version.CHAT.get_key(key=self.chat_id), json.dumps(self.to_dict(), cls=SystemEncoder),
|
||||
version=Cache_Version.CHAT_INFO.get_version(),
|
||||
timeout=60 * 30)
|
||||
|
||||
@staticmethod
|
||||
def map_to_chat_info(chat_info_dict):
|
||||
|
|
|
|||
|
|
@ -446,7 +446,10 @@ class ChatSerializers(serializers.Serializer):
|
|||
def get_chat_info(self):
|
||||
self.is_valid(raise_exception=True)
|
||||
chat_id = self.data.get('chat_id')
|
||||
chat_info: ChatInfo = self.re_open_chat(chat_id)
|
||||
chat_info: ChatInfo = ChatInfo.get_cache(chat_id)
|
||||
if chat_info is None:
|
||||
chat_info: ChatInfo = self.re_open_chat(chat_id)
|
||||
chat_info.set_cache()
|
||||
return chat_info
|
||||
|
||||
def re_open_chat(self, chat_id: str):
|
||||
|
|
|
|||
Loading…
Reference in New Issue