Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: do not change date modified on items when bulk adding

Abdullah Attace53495b76cd
diff --git a/packages/core/src/database/index.ts b/packages/core/src/database/index.ts
index e4e34fc28..ce9672814 100644
--- a/packages/core/src/database/index.ts
+++ b/packages/core/src/database/index.ts
@@ -123,7 +123,7 @@ export interface DatabaseCollection<T, IsAsync extends boolean> {
exists(id: string): AsyncOrSyncResult<IsAsync, boolean>;
count(): AsyncOrSyncResult<IsAsync, number>;
get(id: string): AsyncOrSyncResult<IsAsync, T | undefined>;
- put(items: (T | undefined)[]): Promise<void>;
+ put(items: (T | undefined)[]): Promise<SQLiteItem<T>[]>;
update(ids: string[], partial: Partial<T>): Promise<void>;
ids(options: GroupOptions): AsyncOrSyncResult<IsAsync, string[]>;
records(
diff --git a/packages/core/src/database/sql-cached-collection.ts b/packages/core/src/database/sql-cached-collection.ts
index e95296419..ae87775c4 100644
--- a/packages/core/src/database/sql-cached-collection.ts
+++ b/packages/core/src/database/sql-cached-collection.ts
@@ -106,11 +106,12 @@ export class SQLCachedCollection<
return item;
}
- async put(items: (T | undefined)[]): Promise<void> {
- await this.collection.put(items);
- for (const item of items) {
- if (item) this.cache.set(item.id, item);
+ async put(items: (T | undefined)[]) {
+ const entries = await this.collection.put(items);
+ for (const item of entries) {
+ this.cache.set(item.id, item as T);
}
+ return entries;
}
async update(ids: string[], partial: Partial<T>): Promise<void> {
diff --git a/packages/core/src/database/sql-collection.ts b/packages/core/src/database/sql-collection.ts
index 207a8778d..8b15ece25 100644
--- a/packages/core/src/database/sql-collection.ts
+++ b/packages/core/src/database/sql-collection.ts
@@ -153,11 +153,13 @@ export class SQLCollection<
}
async put(items: (SQLiteItem<T> | undefined)[]) {
- if (items.length <= 0) return;
+ if (items.length <= 0) return [];
const entries = items.reduce((array, item) => {
if (!item) return array;
if (!item.remote) {
- item.dateModified = Date.now();
+ // NOTE: this is intentional
+ // When we are bulk adding items, we shouldn't touch the dateModified
+ // item.dateModified = Date.now();
item.synced = false;
}
delete item.remote;
@@ -165,7 +167,7 @@ export class SQLCollection<
return array;
}, [] as SQLiteItem<T>[]);
- if (entries.length <= 0) return;
+ if (entries.length <= 0) return [];
await this.startTransaction(async (tx) => {
for (const chunk of toChunks(entries, 200)) {
@@ -175,6 +177,7 @@ export class SQLCollection<
.execute();
}
});
+ return entries;
}
async update(