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

This commit is contained in:
Abdullah Atta
2024-03-07 14:59:20 +05:00
parent 42571b0794
commit ce53495b76
3 changed files with 12 additions and 8 deletions

View File

@@ -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(

View File

@@ -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> {

View File

@@ -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(