mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 13:01:00 +00:00
chore(guards): give the linear-fit guard a match floor and keep SQL out of the i18n scan
The linear-fit guard floored only its walk; it now also requires the implementation's call sites it expects. The per-type readings query aliased its driving relation t, which the i18n call-site scanner read as a translation call; it is mt now, as in readLatestEver.
This commit is contained in:
1 parent
071d23537b
commit
be79603d53
2 files changed
+14
-4
No files matched your search
@@ -57,6 +57,14 @@ describe("one least-squares line", () => {
|
||||
),
|
||||
);
|
||||
expect(offenders).toEqual([]);
|
||||
// The six readers now call the implementation: a sweep that finds fewer
|
||||
// call sites read the wrong tree or lost one.
|
||||
const callers = files.filter((file) =>
|
||||
/\b(?:linearFit|fitFromSums|trendLineByTime)\s*\(/.test(
|
||||
stripComments(readFileSync(join(SRC, file), "utf8")),
|
||||
),
|
||||
);
|
||||
expect(callers.length).toBeGreaterThanOrEqual(7);
|
||||
// The implementation itself matches, so the sweep read real files.
|
||||
expect(
|
||||
HAND_ROLLED_SLOPE.test(
|
||||
|
||||
@@ -70,7 +70,9 @@ export async function readRecentReadings(
|
||||
* the multi-metric overview. It read the newest 5 000 rows across all types
|
||||
* at once, so a dense stream (pulse every few minutes) filled the whole read
|
||||
* within days and every other type fell out of the overview. One index
|
||||
* descent per type now bounds each type on its own.
|
||||
* descent per type now bounds each type on its own. The driving relation is
|
||||
* aliased `mt`, the way `readLatestEver` aliases it, so the i18n call-site
|
||||
* scanner does not read the SQL as a translation call.
|
||||
*/
|
||||
export async function readLatestReadingsPerType(
|
||||
userId: string,
|
||||
@@ -81,13 +83,13 @@ export async function readLatestReadingsPerType(
|
||||
const rows = await prisma.$queryRaw<
|
||||
Array<{ type: MeasurementType; value: number; measured_at: Date }>
|
||||
>`
|
||||
SELECT t."type" AS "type", x."value", x."measured_at"
|
||||
FROM unnest(${[...types]}::text[]) AS t("type")
|
||||
SELECT mt."type" AS "type", x."value", x."measured_at"
|
||||
FROM unnest(${[...types]}::text[]) AS mt("type")
|
||||
CROSS JOIN LATERAL (
|
||||
SELECT m."value", m."measured_at"
|
||||
FROM measurements m
|
||||
WHERE m."user_id" = ${userId}
|
||||
AND m."type" = t."type"::measurement_type
|
||||
AND m."type" = mt."type"::measurement_type
|
||||
AND m."deleted_at" IS NULL
|
||||
ORDER BY m."measured_at" DESC
|
||||
LIMIT ${perType}
|
||||
|
||||
Reference in new issue
Block a user