✨feat(core): 优化数据库调用表现 (#2089)

This commit is contained in:
ManyManyTomato
2026-02-01 14:28:51 +08:00
committed by GitHub
parent 7890b39002
commit 203754e300
10 changed files with 341 additions and 44 deletions
+22
View File
@@ -1,5 +1,6 @@
from tortoise import fields
from zhenxun.services.cache.runtime_cache import TaskInfoMemoryCache
from zhenxun.services.db_context import Model
@@ -25,6 +26,27 @@ class TaskInfo(Model):
table = "task_info"
table_description = "被动技能基本信息"
@classmethod
async def create(cls, *args, **kwargs):
result = await super().create(*args, **kwargs)
await TaskInfoMemoryCache.upsert_from_model(result)
return result
@classmethod
async def update_or_create(cls, *args, **kwargs):
result = await super().update_or_create(*args, **kwargs)
await TaskInfoMemoryCache.upsert_from_model(result[0])
return result
async def save(self, *args, **kwargs):
await super().save(*args, **kwargs)
await TaskInfoMemoryCache.upsert_from_model(self)
async def delete(self, *args, **kwargs):
module = self.module
await super().delete(*args, **kwargs)
await TaskInfoMemoryCache.remove(module)
@classmethod
async def _run_script(cls):
return [