Skip to content

Commit f9000b9

Browse files
committed
fix: batch update global->account
1 parent 9267052 commit f9000b9

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inspatial/cloud",
3-
"version": "0.7.22",
3+
"version": "0.7.23",
44
"license": "Apache-2.0",
55
"exports": {
66
".": "./mod.ts",

src/orm/entry/entry.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,40 @@ export class Entry<
442442
field: registryField.targetValueField,
443443
};
444444
}
445-
445+
if (this._systemGlobal) {
446+
// if this is a cloud_global entryType, check if the target is account-scoped, and batch update per-account
447+
const { systemGlobal, name } = this._orm.getEntryType(
448+
registryField.targetEntryType as EntryName,
449+
);
450+
if (!systemGlobal) {
451+
const sysOrm = this._orm.withUser(this._orm.systemGobalUser);
452+
const { rows: accounts, rowCount } = await sysOrm.getEntryList(
453+
"account",
454+
{
455+
columns: ["id"],
456+
limit: 0,
457+
},
458+
);
459+
// this._inCloud.inLog.warn(
460+
// `${name} is not global, batch update of ${fieldKey} from ${this._name} for ${rowCount} accounts`,
461+
// { compact: true },
462+
// );
463+
for (const { id } of accounts) {
464+
const orm = this._orm.withAccount(id);
465+
await orm.batchUpdateField(
466+
registryField.targetEntryType,
467+
field,
468+
this._modifiedValues.get(fieldKey)!.to,
469+
[{
470+
field: registryField.targetIdField,
471+
op: "=",
472+
value: this["$id" as keyof typeof this] as string,
473+
}],
474+
);
475+
}
476+
continue;
477+
}
478+
}
446479
await this._orm.batchUpdateField(
447480
registryField.targetEntryType,
448481
field,

0 commit comments

Comments
 (0)