refactor(insights): strip INDEXED BY pins via an attribute loop

Simplify-pass fold: the four copy-pasted .replace blocks meant a\nfifth pinned statement could forget its strip line — a hard 'no such\nindex' crash on read-only DBs, the exact bug the fallback prevents.\nLoop over the attribute names instead.
This commit is contained in:
kshitij 2026-08-03 17:24:25 +05:30 committed by kshitij
parent 401e054d59
commit 5017deb3db
1 changed files with 10 additions and 8 deletions

View File

@ -114,14 +114,16 @@ class InsightsEngine:
self._has_assistant_calls_index = False
if not self._has_assistant_calls_index:
_strip = f" INDEXED BY {self._MESSAGES_ASSISTANT_CALLS_INDEX}"
self._GET_TOOL_CALLS_WITH_SOURCE = (
self._GET_TOOL_CALLS_WITH_SOURCE.replace(_strip, "")
)
self._GET_TOOL_CALLS_ALL = self._GET_TOOL_CALLS_ALL.replace(_strip, "")
self._GET_SKILL_CALLS_WITH_SOURCE = (
self._GET_SKILL_CALLS_WITH_SOURCE.replace(_strip, "")
)
self._GET_SKILL_CALLS_ALL = self._GET_SKILL_CALLS_ALL.replace(_strip, "")
# Loop over every pinned statement so adding a new one can't
# forget its strip line (which would be a hard `no such index`
# crash on read-only DBs — the exact bug this fallback prevents).
for _attr in (
"_GET_TOOL_CALLS_WITH_SOURCE",
"_GET_TOOL_CALLS_ALL",
"_GET_SKILL_CALLS_WITH_SOURCE",
"_GET_SKILL_CALLS_ALL",
):
setattr(self, _attr, getattr(self, _attr).replace(_strip, ""))
def generate(self, days: int = 30, source: str = None) -> Dict[str, Any]:
"""