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>;
|
exists(id: string): AsyncOrSyncResult<IsAsync, boolean>;
|
||||||
count(): AsyncOrSyncResult<IsAsync, number>;
|
count(): AsyncOrSyncResult<IsAsync, number>;
|
||||||
get(id: string): AsyncOrSyncResult<IsAsync, T | undefined>;
|
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>;
|
update(ids: string[], partial: Partial<T>): Promise<void>;
|
||||||
ids(options: GroupOptions): AsyncOrSyncResult<IsAsync, string[]>;
|
ids(options: GroupOptions): AsyncOrSyncResult<IsAsync, string[]>;
|
||||||
records(
|
records(
|
||||||
|
|||||||
@@ -106,11 +106,12 @@ export class SQLCachedCollection<
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
async put(items: (T | undefined)[]): Promise<void> {
|
async put(items: (T | undefined)[]) {
|
||||||
await this.collection.put(items);
|
const entries = await this.collection.put(items);
|
||||||
for (const item of items) {
|
for (const item of entries) {
|
||||||
if (item) this.cache.set(item.id, item);
|
this.cache.set(item.id, item as T);
|
||||||
}
|
}
|
||||||
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(ids: string[], partial: Partial<T>): Promise<void> {
|
async update(ids: string[], partial: Partial<T>): Promise<void> {
|
||||||
|
|||||||
@@ -153,11 +153,13 @@ export class SQLCollection<
|
|||||||
}
|
}
|
||||||
|
|
||||||
async put(items: (SQLiteItem<T> | undefined)[]) {
|
async put(items: (SQLiteItem<T> | undefined)[]) {
|
||||||
if (items.length <= 0) return;
|
if (items.length <= 0) return [];
|
||||||
const entries = items.reduce((array, item) => {
|
const entries = items.reduce((array, item) => {
|
||||||
if (!item) return array;
|
if (!item) return array;
|
||||||
if (!item.remote) {
|
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;
|
item.synced = false;
|
||||||
}
|
}
|
||||||
delete item.remote;
|
delete item.remote;
|
||||||
@@ -165,7 +167,7 @@ export class SQLCollection<
|
|||||||
return array;
|
return array;
|
||||||
}, [] as SQLiteItem<T>[]);
|
}, [] as SQLiteItem<T>[]);
|
||||||
|
|
||||||
if (entries.length <= 0) return;
|
if (entries.length <= 0) return [];
|
||||||
|
|
||||||
await this.startTransaction(async (tx) => {
|
await this.startTransaction(async (tx) => {
|
||||||
for (const chunk of toChunks(entries, 200)) {
|
for (const chunk of toChunks(entries, 200)) {
|
||||||
@@ -175,6 +177,7 @@ export class SQLCollection<
|
|||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(
|
async update(
|
||||||
|
|||||||
Reference in New Issue
Block a user