Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

feat: do bulk actions sequentially instead of concurrently to avoid locking issues, really need to switch to a bulk api

tonyaelliecaad3d8bb339
diff --git a/frontend/components/Item/View/ItemChangeDetails.vue b/frontend/components/Item/View/ItemChangeDetails.vue
index ef0824b1..bbf36325 100644
--- a/frontend/components/Item/View/ItemChangeDetails.vue
+++ b/frontend/components/Item/View/ItemChangeDetails.vue
@@ -92,39 +92,38 @@
saving.value = true;
- await Promise.allSettled(
- items.value.map(async item => {
- const patch: ItemPatch = {
- id: item.id,
- };
-
- if (enabled.changeLocation) {
- patch.locationId = location!.id;
- }
+ // Process items sequentially to avoid database locking issues with concurrent write transactions
+ for (const item of items.value) {
+ const patch: ItemPatch = {
+ id: item.id,
+ };
+
+ if (enabled.changeLocation) {
+ patch.locationId = location!.id;
+ }
- let currentTags = item.tags.map(l => l.id);
+ let currentTags = item.tags.map(l => l.id);
- if (enabled.addTags) {
- currentTags = currentTags.concat(tagsToAdd);
- }
+ if (enabled.addTags) {
+ currentTags = currentTags.concat(tagsToAdd);
+ }
- if (enabled.removeTags) {
- currentTags = currentTags.filter(l => !tagsToRemove.includes(l));
- }
+ if (enabled.removeTags) {
+ currentTags = currentTags.filter(l => !tagsToRemove.includes(l));
+ }
- if (enabled.addTags || enabled.removeTags) {
- patch.tagIds = Array.from(new Set(currentTags));
- }
+ if (enabled.addTags || enabled.removeTags) {
+ patch.tagIds = Array.from(new Set(currentTags));
+ }
- const { error, data } = await api.items.patch(item.id, patch);
+ const { error, data } = await api.items.patch(item.id, patch);
- if (error) {
- console.error("failed to update item", item.id, data);
- toast.error(t("components.item.view.change_details.failed_to_update_item"));
- return;
- }
- })
- );
+ if (error) {
+ console.error("failed to update item", item.id, data);
+ toast.error(t("components.item.view.change_details.failed_to_update_item"));
+ continue;
+ }
+ }
closeDialog(DialogID.ItemChangeDetails, true);
enabled.changeLocation = false;
diff --git a/frontend/components/Item/View/table/data-table-dropdown.vue b/frontend/components/Item/View/table/data-table-dropdown.vue
index a51e205b..a8e67eac 100644
--- a/frontend/components/Item/View/table/data-table-dropdown.vue
+++ b/frontend/components/Item/View/table/data-table-dropdown.vue
@@ -130,34 +130,36 @@
return;
}
- await Promise.allSettled(
- ids.map(id =>
- api.items.delete(id).catch(err => {
- toast.error(t("components.item.view.table.dropdown.error_deleting"));
- console.error(err);
- })
- )
- );
+ // Process deletions sequentially to avoid database locking issues with concurrent write transactions
+ for (const id of ids) {
+ try {
+ await api.items.delete(id);
+ } catch (err) {
+ toast.error(t("components.item.view.table.dropdown.error_deleting"));
+ console.error(err);
+ }
+ }
resetSelection();
};
const duplicateItems = async (ids: string[]) => {
- await Promise.allSettled(
- ids.map(id =>
- api.items
- .duplicate(id, {
- copyMaintenance: preferences.value.duplicateSettings.copyMaintenance,
- copyAttachments: preferences.value.duplicateSettings.copyAttachments,
- copyCustomFields: preferences.value.duplicateSettings.copyCustomFields,
- copyPrefix: preferences.value.duplicateSettings.copyPrefixOverride ?? t("items.duplicate.prefix"),
- })
- .catch(err => {
- toast.error(t("components.item.view.table.dropdown.error_duplicating"));
- console.error(err);
- })
- )
- );
+ // Process items sequentially to avoid database locking issues
+ // SQLite (and other single-writer databases) can experience lock contention
+ // when multiple transactions try to write simultaneously
+ for (const id of ids) {
+ try {
+ await api.items.duplicate(id, {
+ copyMaintenance: preferences.value.duplicateSettings.copyMaintenance,
+ copyAttachments: preferences.value.duplicateSettings.copyAttachments,
+ copyCustomFields: preferences.value.duplicateSettings.copyCustomFields,
+ copyPrefix: preferences.value.duplicateSettings.copyPrefixOverride ?? t("items.duplicate.prefix"),
+ });
+ } catch (err) {
+ toast.error(t("components.item.view.table.dropdown.error_duplicating"));
+ console.error(err);
+ }
+ }
resetSelection();
};