Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Only update item level record if one of the properties have changed (#1404)
Leendert de Borstb95a0e5a4786
diff --git a/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts b/apps/browser-extension/src/utils/db/repositories/ItemRepository.tsindex 66c398dcc..5bc7db2a1 100644--- a/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts+++ b/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts@@ -177,15 +177,31 @@ export class ItemRepository extends BaseRepository {// 1. Handle Logoconst logoId = this.resolveLogoId(item, currentDateTime);- // 2. Update Item- this.client.executeUpdate(ItemQueries.UPDATE_ITEM, [- item.Name ?? null,- item.ItemType,- item.FolderId ?? null,- logoId,- currentDateTime,- item.Id- ]);+ // 2. Update Item only if item-level fields changed+ const existing = this.client.executeQuery<{+ Name: string | null;+ ItemType: number;+ FolderId: string | null;+ LogoId: string | null;+ }>(`SELECT Name, ItemType, FolderId, LogoId FROM Items WHERE Id = ?`, [item.Id])[0];++ if (existing) {+ const nameChanged = (item.Name ?? null) !== existing.Name;+ const itemTypeChanged = String(item.ItemType) !== String(existing.ItemType);+ const folderIdChanged = (item.FolderId ?? null) !== existing.FolderId;+ const logoIdChanged = logoId !== null && logoId !== existing.LogoId;++ if (nameChanged || itemTypeChanged || folderIdChanged || logoIdChanged) {+ this.client.executeUpdate(ItemQueries.UPDATE_ITEM, [+ item.Name ?? null,+ item.ItemType,+ item.FolderId ?? null,+ logoId,+ currentDateTime,+ item.Id+ ]);+ }+ }// 3. Track history for fields that have EnableHistory=true before updatingawait this.trackFieldHistory(item.Id, item.Fields, currentDateTime);diff --git a/apps/mobile-app/app/(tabs)/items/add-edit.tsx b/apps/mobile-app/app/(tabs)/items/add-edit.tsxindex 679543455..482b0fcdf 100644--- a/apps/mobile-app/app/(tabs)/items/add-edit.tsx+++ b/apps/mobile-app/app/(tabs)/items/add-edit.tsx@@ -811,14 +811,16 @@ export default function AddEditItemScreen(): React.ReactNode {await dbContext.sqliteClient!.items.create(itemToSave, attachments, totpCodes);}- // Emit event to notify list and detail views to refresh- emitter.emit('credentialChanged', itemToSave.Id);},{/*** Handle successful save*/onSuccess: () => {+ // Emit event to notify list and detail views to refresh+ // Must be after sync completes so merged data is available+ emitter.emit('credentialChanged', itemToSave.Id);+setHasUnsavedChanges(false);if (serviceUrl && !isEditMode) {diff --git a/apps/mobile-app/utils/db/repositories/ItemRepository.ts b/apps/mobile-app/utils/db/repositories/ItemRepository.tsindex c8abf8e63..9817bc3e5 100644--- a/apps/mobile-app/utils/db/repositories/ItemRepository.ts+++ b/apps/mobile-app/utils/db/repositories/ItemRepository.ts@@ -309,15 +309,30 @@ export class ItemRepository extends BaseRepository {return this.withTransaction(async () => {const now = this.now();- // 1. Update Item- await this.client.executeUpdate(ItemQueries.UPDATE_ITEM, [- item.Name,- item.ItemType,- item.FolderId || null,- null, // LogoId update handled separately if needed- now,- item.Id- ]);+ // 1. Update Item only if item-level fields changed+ const existing = await this.client.executeQuery<{+ Name: string | null;+ ItemType: string | null;+ FolderId: string | null;+ }>(`SELECT Name, ItemType, FolderId FROM Items WHERE Id = ?`, [item.Id]);++ if (existing.length > 0) {+ const existingItem = existing[0];+ const nameChanged = item.Name !== existingItem.Name;+ const itemTypeChanged = String(item.ItemType) !== String(existingItem.ItemType);+ const folderIdChanged = (item.FolderId || null) !== existingItem.FolderId;++ if (nameChanged || itemTypeChanged || folderIdChanged) {+ await this.client.executeUpdate(ItemQueries.UPDATE_ITEM, [+ item.Name,+ item.ItemType,+ item.FolderId || null,+ null, // LogoId update handled separately if needed+ now,+ item.Id+ ]);+ }+ }// 2. Update FieldValues using preserve-and-track strategyawait this.updateFieldValues(item.Id, item.Fields, now);diff --git a/apps/server/AliasVault.Client/Services/ItemService.cs b/apps/server/AliasVault.Client/Services/ItemService.csindex 8bcd123ce..13cd55092 100644--- a/apps/server/AliasVault.Client/Services/ItemService.cs+++ b/apps/server/AliasVault.Client/Services/ItemService.cs@@ -276,12 +276,20 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf// Check if item type has changedvar typeChanged = existingItem.ItemType != item.ItemType;- // Update basic item info- existingItem.Name = item.Name;- existingItem.ItemType = item.ItemType;- existingItem.LogoId = item.LogoId;- existingItem.FolderId = item.FolderId;- existingItem.UpdatedAt = updateDateTime;+ // Update basic item info only if values changed+ var itemLevelChanged = existingItem.Name != item.Name ||+ existingItem.ItemType != item.ItemType ||+ existingItem.LogoId != item.LogoId ||+ existingItem.FolderId != item.FolderId;++ if (itemLevelChanged)+ {+ existingItem.Name = item.Name;+ existingItem.ItemType = item.ItemType;+ existingItem.LogoId = item.LogoId;+ existingItem.FolderId = item.FolderId;+ existingItem.UpdatedAt = updateDateTime;+ }// Clear inapplicable fields/relations when type changesif (typeChanged && item.ItemType != null)