Skip to content

Commit ae27288

Browse files
authored
mcm : Fix hits and last access when re-index (#115)
1 parent 1065046 commit ae27288

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

mcm/model_cache_manager/data/database.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,13 @@ def _upsert_kernel(
154154
)
155155

156156
stmt = sqlite_insert(KernelOrm).values(kernel_values)
157+
# Preserve runtime statistics during updates
158+
# These fields should not be overwritten during re-indexing
159+
preserved_fields = {"runtime_hits", "last_access_time"}
157160
update_dict = {
158161
col.name: getattr(stmt.excluded, col.name)
159162
for col in KernelOrm.__table__.columns
160-
if col.name not in ("hash", "cache_dir")
163+
if col.name not in ("hash", "cache_dir") and col.name not in preserved_fields
161164
}
162165
session.execute(
163166
stmt.on_conflict_do_update(
@@ -476,10 +479,13 @@ def _upsert_vllm_kernel(
476479
"rank_x_y",
477480
"artifact_shape", # Always included in primary key for VllmKernelOrm
478481
]
482+
# Preserve runtime statistics during updates
483+
# These fields should not be overwritten during re-indexing
484+
preserved_fields = {"runtime_hits", "last_access_time"}
479485
update_dict = {
480486
col.name: getattr(stmt.excluded, col.name)
481487
for col in VllmKernelOrm.__table__.columns
482-
if col.name not in primary_key_fields
488+
if col.name not in primary_key_fields and col.name not in preserved_fields
483489
}
484490
session.execute(
485491
stmt.on_conflict_do_update(

mcm/model_cache_manager/data/vllm_legacy_database.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,14 @@ def _upsert_legacy_kernel(
186186
)
187187

188188
stmt = sqlite_insert(VllmLegacyKernelOrm).values(kernel_values)
189+
# Preserve runtime statistics during updates
190+
# These fields should not be overwritten during re-indexing
191+
preserved_fields = {"runtime_hits", "last_access_time"}
189192
update_dict = {
190193
col.name: getattr(stmt.excluded, col.name)
191194
for col in VllmLegacyKernelOrm.__table__.columns
192195
if col.name not in ("cache_dir", "vllm_hash", "triton_cache_key", "rank_x_y")
196+
and col.name not in preserved_fields
193197
}
194198
session.execute(
195199
stmt.on_conflict_do_update(

0 commit comments

Comments
 (0)