@gravity-rail/cli 0.32.0 → 0.33.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.
package/dist/lib.js CHANGED
@@ -10355,12 +10355,81 @@ var ActivityRefResolver = class {
10355
10355
  forWorkspace.set(`${ref.kind}|${ref.uuid}`, ref);
10356
10356
  byWorkspace.set(ref.workspaceUuid, forWorkspace);
10357
10357
  }
10358
+ const groups = [...byWorkspace].map(
10359
+ ([workspaceUuid, wanted]) => [workspaceUuid, [...wanted.values()]]
10360
+ );
10361
+ if (this.options.orgUuid) {
10362
+ await this.primeOrg(this.options.orgUuid, groups);
10363
+ return;
10364
+ }
10358
10365
  await Promise.all(
10359
- [...byWorkspace].map(
10360
- ([workspaceUuid, wanted]) => this.primeWorkspace(workspaceUuid, [...wanted.values()])
10361
- )
10366
+ groups.map(([workspaceUuid, wanted]) => this.primeWorkspace(workspaceUuid, wanted))
10362
10367
  );
10363
10368
  }
10369
+ /**
10370
+ * One org call per chunk, each carrying whole workspace groups.
10371
+ *
10372
+ * The server's cap is over the whole request rather than per workspace, and
10373
+ * it accepts each workspace at most once per request — so a group larger
10374
+ * than the cap is split across requests, and smaller groups ride together
10375
+ * until the next one would not fit.
10376
+ */
10377
+ async primeOrg(orgUuid, groups) {
10378
+ const chunks = [];
10379
+ let current = [];
10380
+ let size = 0;
10381
+ for (const [workspaceUuid, refs] of groups) {
10382
+ for (let start = 0; start < refs.length; start += MAX_REFS_PER_BATCH) {
10383
+ const slice = refs.slice(start, start + MAX_REFS_PER_BATCH);
10384
+ if (size + slice.length > MAX_REFS_PER_BATCH && current.length > 0) {
10385
+ chunks.push(current);
10386
+ current = [];
10387
+ size = 0;
10388
+ }
10389
+ current.push([workspaceUuid, slice]);
10390
+ size += slice.length;
10391
+ }
10392
+ }
10393
+ if (current.length > 0) chunks.push(current);
10394
+ for (const chunk of chunks) {
10395
+ const key = `org:${orgUuid}|${chunk.map(
10396
+ ([workspaceUuid, refs]) => `${workspaceUuid}:${refs.map((ref) => `${ref.kind}|${ref.uuid}`).sort().join(",")}`
10397
+ ).sort().join(";")}`;
10398
+ const pending = this.inFlight.get(key) ?? this.fetchOrgChunk(orgUuid, chunk, key);
10399
+ this.inFlight.set(key, pending);
10400
+ await pending;
10401
+ }
10402
+ }
10403
+ /** One org batch call, seeded into the same per-ref cache. */
10404
+ async fetchOrgChunk(orgUuid, chunk, key) {
10405
+ try {
10406
+ this.fetches += 1;
10407
+ const response = await this.client.resolveOrgEntityRefs(orgUuid, {
10408
+ workspaces: chunk.map(([workspaceUuid, refs]) => ({
10409
+ workspaceUuid,
10410
+ refs: refs.map((ref) => ({ kind: ref.kind, uuid: ref.uuid }))
10411
+ }))
10412
+ });
10413
+ const answered = new Map(
10414
+ response.workspaces.map((group) => [
10415
+ group.workspaceUuid,
10416
+ new Map(group.refs.map((entry) => [`${entry.kind}|${entry.uuid}`, entry]))
10417
+ ])
10418
+ );
10419
+ for (const [workspaceUuid, refs] of chunk) {
10420
+ const byKey = answered.get(workspaceUuid);
10421
+ if (!byKey) continue;
10422
+ for (const ref of refs) {
10423
+ const entry = byKey.get(`${ref.kind}|${ref.uuid}`);
10424
+ if (!entry) continue;
10425
+ const resolution = batchResolution(ref, entry);
10426
+ if (resolution) this.cache.set(this.cacheKey(ref), Promise.resolve(resolution));
10427
+ }
10428
+ }
10429
+ } catch {
10430
+ this.inFlight.delete(key);
10431
+ }
10432
+ }
10364
10433
  async primeWorkspace(workspaceUuid, refs) {
10365
10434
  for (let start = 0; start < refs.length; start += MAX_REFS_PER_BATCH) {
10366
10435
  const chunk = refs.slice(start, start + MAX_REFS_PER_BATCH);
@@ -10612,8 +10681,10 @@ function globalFlags(ctx) {
10612
10681
  return flags;
10613
10682
  }
10614
10683
  function resolverFor(hctx) {
10684
+ const mount = resolveActivityMount(hctx.args);
10615
10685
  return new ActivityRefResolver(requireAuth(hctx.ctx).apiClient, {
10616
- bare: hctx.args.ids === true
10686
+ bare: hctx.args.ids === true,
10687
+ orgUuid: mount.kind === "org" ? mount.uuid : void 0
10617
10688
  });
10618
10689
  }
10619
10690
  function isAggregate(response) {