mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
core: do not change date modified on items when bulk adding
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user