@ai-matrx/records 0.79.1 → 0.80.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -176,6 +176,19 @@ function compileSort(sort, shape) {
176
176
  return { ok: true, data: out };
177
177
  }
178
178
 
179
+ // src/core/primedBundle.ts
180
+ var PRIMED_TTL_MS = 15e3;
181
+ var primed = /* @__PURE__ */ new Map();
182
+ var primedKey = (organizationId, tableId, viewId) => `${organizationId}|${tableId}|${viewId ?? ""}`;
183
+ function takePrimedTablePageBundle(organizationId, tableId, viewId) {
184
+ if (!organizationId) return null;
185
+ const key = primedKey(organizationId, tableId, viewId);
186
+ const held = primed.get(key);
187
+ if (!held) return null;
188
+ primed.delete(key);
189
+ return Date.now() - held.at < PRIMED_TTL_MS ? held.answer : null;
190
+ }
191
+
179
192
  // src/archive.ts
180
193
  var DEFAULT_ARCHIVE_LANE = "org";
181
194
 
@@ -2541,13 +2554,20 @@ function createRecordsClient(given) {
2541
2554
  }
2542
2555
  async function fillBundle(tableId, viewId) {
2543
2556
  try {
2544
- const response = await config.dataSource.rpc(
2545
- "table_page_bundle",
2546
- { p_organization_id: org, p_table_id: tableId, p_view_id: typeof viewId === "string" ? viewId : null },
2547
- { schema }
2548
- );
2557
+ const view = typeof viewId === "string" ? viewId : null;
2558
+ const usable = (r) => r !== null && !r.error && r.data !== null && typeof r.data === "object" && Array.isArray(r.data.parts);
2559
+ const primedAnswer = takePrimedTablePageBundle(org, tableId, view);
2560
+ let response = primedAnswer ? await primedAnswer : null;
2561
+ if (!usable(response)) {
2562
+ response = await config.dataSource.rpc(
2563
+ "table_page_bundle",
2564
+ { p_organization_id: org, p_table_id: tableId, p_view_id: view },
2565
+ { schema }
2566
+ );
2567
+ }
2568
+ if (!usable(response)) return;
2549
2569
  const answer = response.data;
2550
- if (response.error || !answer || !Array.isArray(answer.parts)) return;
2570
+ if (!answer || !Array.isArray(answer.parts)) return;
2551
2571
  const now = Date.now();
2552
2572
  for (const part of answer.parts) {
2553
2573
  if (part.error !== void 0 || part.data === void 0) continue;