phase 3: all variable cateogry references simplified
All checks were successful
Deploy / deploy (push) Successful in 1m33s
Security Tests / security-non-db (push) Successful in 20s
Security Tests / security-db (push) Successful in 26s

This commit is contained in:
2026-03-16 15:20:12 -05:00
parent a430dfadcf
commit 4a63309153
5 changed files with 319 additions and 507 deletions

View File

@@ -333,19 +333,12 @@ function CategoriesSettingsInner(
await categoriesApi.delete(cat.id);
}
// Creates
const toCreate = normalizedCats.filter((c) => c._isNew && !c._isDeleted);
for (const cat of toCreate) {
await categoriesApi.create({
name: normalizeName(cat.name),
percent: cat.percent,
priority: cat.priority,
isSavings: cat.isSavings,
});
}
// Updates
const toUpdate = normalizedCats.filter((c) => !c._isNew && !c._isDeleted);
const updateOps: Array<{
id: string;
patch: Partial<Row>;
percentDelta: number;
}> = [];
for (const local of toUpdate) {
const server = serverCats.find((s) => s.id === local.id);
if (!server) continue;
@@ -358,10 +351,37 @@ function CategoriesSettingsInner(
patch.isSavings = local.isSavings;
if (Object.keys(patch).length > 0) {
await categoriesApi.update(local.id, patch);
updateOps.push({
id: local.id,
patch,
// Apply percent decreases first to avoid temporary >100 totals on server.
percentDelta: local.percent - server.percent,
});
}
}
const preCreateUpdates = updateOps.filter((op) => op.percentDelta < 0);
const postCreateUpdates = updateOps.filter((op) => op.percentDelta >= 0);
for (const op of preCreateUpdates) {
await categoriesApi.update(op.id, op.patch);
}
// Creates
const toCreate = normalizedCats.filter((c) => c._isNew && !c._isDeleted);
for (const cat of toCreate) {
await categoriesApi.create({
name: normalizeName(cat.name),
percent: cat.percent,
priority: cat.priority,
isSavings: cat.isSavings,
});
}
for (const op of postCreateUpdates) {
await categoriesApi.update(op.id, op.patch);
}
if (hasNew) {
try {
await categoriesApi.rebalance();