@easy-cms/core 1.30.0 → 1.30.1

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.
@@ -8101,7 +8101,7 @@ function cacheableResponse(request, body, status, headers, times, tags) {
8101
8101
  }
8102
8102
 
8103
8103
  // src/version.ts
8104
- var VERSION = true ? "1.30.0" : "0.0.0-dev";
8104
+ var VERSION = true ? "1.30.1" : "0.0.0-dev";
8105
8105
 
8106
8106
  // src/telemetry.ts
8107
8107
  var DB_CALLS = /* @__PURE__ */ new Set([
@@ -12931,21 +12931,42 @@ async function readable(cms, c, who) {
12931
12931
  return false;
12932
12932
  }
12933
12933
  }
12934
- async function adminCounts(cms, who) {
12934
+ var LIST_TOTAL_MAX = 1e4;
12935
+ var MENU_COUNTS_TTL = 3e4;
12936
+ var kept = /* @__PURE__ */ new WeakMap();
12937
+ async function adminCounts(cms, who, options = {}) {
12938
+ const key = `${String(who.user.id)}:${who.user.apiKey ? "key" : "user"}:${JSON.stringify(who.context)}`;
12939
+ const cache = kept.get(cms) ?? /* @__PURE__ */ new Map();
12940
+ kept.set(cms, cache);
12941
+ const now = Date.now();
12942
+ const hit = cache.get(key);
12943
+ if (hit && !options.fresh && now - hit.at < MENU_COUNTS_TTL) return hit.value;
12935
12944
  const counts = {};
12936
12945
  const badges = {};
12946
+ const more = [];
12937
12947
  await Promise.all(
12938
12948
  listed(cms).map(async (c) => {
12939
12949
  const read2 = { ...who, overrideAccess: false, draft: true };
12940
12950
  try {
12941
- if (c.admin?.count !== false) counts[c.slug] = await cms.count(c.slug, read2);
12951
+ if (c.admin?.count !== false) {
12952
+ const total = await cms.count(c.slug, { ...read2, max: LIST_TOTAL_MAX });
12953
+ counts[c.slug] = Math.min(total, LIST_TOTAL_MAX);
12954
+ if (total > LIST_TOTAL_MAX) more.push(c.slug);
12955
+ }
12942
12956
  if (c.admin?.badge)
12943
- badges[c.slug] = await cms.count(c.slug, { ...read2, where: c.admin.badge.where });
12957
+ badges[c.slug] = await cms.count(c.slug, {
12958
+ ...read2,
12959
+ where: c.admin.badge.where,
12960
+ max: LIST_TOTAL_MAX
12961
+ });
12944
12962
  } catch {
12945
12963
  }
12946
12964
  })
12947
12965
  );
12948
- return { counts, badges };
12966
+ const value = { counts, badges, more };
12967
+ for (const [k, entry] of cache) if (now - entry.at >= MENU_COUNTS_TTL) cache.delete(k);
12968
+ cache.set(key, { at: now, value });
12969
+ return value;
12949
12970
  }
12950
12971
  async function adminSearch(cms, who, q, perCollection = 5) {
12951
12972
  const query = q.trim().slice(0, 100);
@@ -13233,7 +13254,6 @@ function parseDepth(url) {
13233
13254
 
13234
13255
  // src/rest/handler.ts
13235
13256
  var SCHEDULED_RANGE_LIMIT = 500;
13236
- var LIST_TOTAL_MAX = 1e4;
13237
13257
  var CSRF_COOKIE = "ecms-csrf";
13238
13258
  var CSRF_HEADER = "x-csrf-token";
13239
13259
  var MAX_BODY_BYTES = 1024 * 1024;
@@ -13948,7 +13968,14 @@ async function route(cms, ctx, method, path, options) {
13948
13968
  if (second === "schema" && third === void 0)
13949
13969
  return { body: await adminSchema(cms, ctx.user, ctx.url.origin, ctx.context) };
13950
13970
  if (second === "counts" && third === void 0)
13951
- return { body: await adminCounts(cms, { user: ctx.user, context: ctx.context }) };
13971
+ return {
13972
+ body: await adminCounts(
13973
+ cms,
13974
+ { user: ctx.user, context: ctx.context },
13975
+ // `?fresh`: after creating or deleting, not the numbers kept for 30 s.
13976
+ { fresh: ctx.url.searchParams.has("fresh") }
13977
+ )
13978
+ };
13952
13979
  if (second === "search" && third === void 0)
13953
13980
  return {
13954
13981
  body: {
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  silentLogger,
29
29
  slugify,
30
30
  verifyWebhook
31
- } from "./chunk-JTBPGZMF.js";
31
+ } from "./chunk-W3FVQ2CA.js";
32
32
  import {
33
33
  matchesCondition
34
34
  } from "./chunk-U266LV4M.js";
package/dist/internal.js CHANGED
@@ -58,7 +58,7 @@ import {
58
58
  verifyPassword,
59
59
  verifyTurnstile,
60
60
  writeBackupFile
61
- } from "./chunk-JTBPGZMF.js";
61
+ } from "./chunk-W3FVQ2CA.js";
62
62
  import {
63
63
  conditionIssues
64
64
  } from "./chunk-U266LV4M.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/core",
3
- "version": "1.30.0",
3
+ "version": "1.30.1",
4
4
  "description": "Embedded, code-first headless CMS for Nuxt and Next.js",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -70,7 +70,7 @@
70
70
  }
71
71
  },
72
72
  "devDependencies": {
73
- "@opentelemetry/api": "~1.9.1",
73
+ "@opentelemetry/api": "~1.10.0",
74
74
  "sharp": "^0.35.5"
75
75
  },
76
76
  "scripts": {