@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.
@@ -10,6 +10,19 @@ import {
10
10
  useRef
11
11
  } from "react";
12
12
 
13
+ // src/core/primedBundle.ts
14
+ var PRIMED_TTL_MS = 15e3;
15
+ var primed = /* @__PURE__ */ new Map();
16
+ var primedKey = (organizationId, tableId, viewId) => `${organizationId}|${tableId}|${viewId ?? ""}`;
17
+ function takePrimedTablePageBundle(organizationId, tableId, viewId) {
18
+ if (!organizationId) return null;
19
+ const key = primedKey(organizationId, tableId, viewId);
20
+ const held = primed.get(key);
21
+ if (!held) return null;
22
+ primed.delete(key);
23
+ return Date.now() - held.at < PRIMED_TTL_MS ? held.answer : null;
24
+ }
25
+
13
26
  // src/archive.ts
14
27
  var ARCHIVE_LANES = ["mine", "org"];
15
28
  var DEFAULT_ARCHIVE_LANE = "org";
@@ -4073,13 +4086,20 @@ function createRecordsClient(given) {
4073
4086
  }
4074
4087
  async function fillBundle(tableId, viewId) {
4075
4088
  try {
4076
- const response = await config.dataSource.rpc(
4077
- "table_page_bundle",
4078
- { p_organization_id: org, p_table_id: tableId, p_view_id: typeof viewId === "string" ? viewId : null },
4079
- { schema }
4080
- );
4089
+ const view = typeof viewId === "string" ? viewId : null;
4090
+ const usable = (r) => r !== null && !r.error && r.data !== null && typeof r.data === "object" && Array.isArray(r.data.parts);
4091
+ const primedAnswer = takePrimedTablePageBundle(org, tableId, view);
4092
+ let response = primedAnswer ? await primedAnswer : null;
4093
+ if (!usable(response)) {
4094
+ response = await config.dataSource.rpc(
4095
+ "table_page_bundle",
4096
+ { p_organization_id: org, p_table_id: tableId, p_view_id: view },
4097
+ { schema }
4098
+ );
4099
+ }
4100
+ if (!usable(response)) return;
4081
4101
  const answer = response.data;
4082
- if (response.error || !answer || !Array.isArray(answer.parts)) return;
4102
+ if (!answer || !Array.isArray(answer.parts)) return;
4083
4103
  const now = Date.now();
4084
4104
  for (const part of answer.parts) {
4085
4105
  if (part.error !== void 0 || part.data === void 0) continue;