Add granular timing to get_template: separate execute vs fetch time

This commit is contained in:
YueGuobin 2026-06-15 23:33:19 +08:00
parent e90fb0774c
commit b3619a3c00
No known key found for this signature in database

View File

@ -55,14 +55,20 @@ class TemplatesRepository(BaseRepository):
async def get_template(self, template_id: UUID) -> Union[None, models.Template]:
import time
_t0 = time.time()
query = select(models.Template).\
options(selectinload(models.Template.images)).\
where(models.Template.template_id == template_id)
_t1 = time.time()
result = await self._db_session.execute(query)
elapsed = time.time() - _t0
if elapsed > 0.1:
log.warning(f"[CTRL-TIMING] DB get_template SLOW template_id={template_id} elapsed={elapsed:.3f}s")
return result.scalars().first()
_t2 = time.time()
row = result.scalars().first()
_t3 = time.time()
if _t3 - _t0 > 0.1:
log.warning(f"[CTRL-TIMING] DB get_template SLOW template_id={template_id} "
f"execute={_t2-_t1:.3f}s fetch={_t3-_t2:.3f}s total={_t3-_t0:.3f}s")
return row
async def get_template_by_name_and_version(self, name: str, version: str) -> Union[None, models.Template]: