Store: implement updating store in bulk.

master
Tom Hacohen 4 years ago
parent 6e3bb42f96
commit 626771d2c5

@ -107,6 +107,23 @@ export const unsetCacheItem = createAction(
} }
); );
export const setCacheItemMulti = createAction(
"SET_CACHE_ITEM_MULTI",
async (_colUid: string, itemMgr: Etebase.CollectionItemManager, items: Etebase.CollectionItem[]) => {
const ret = [];
for (const item of items) {
ret.push(Etebase.toBase64(await itemMgr.cacheSave(item)));
}
return ret;
},
(colUid: string, _itemMgr: Etebase.CollectionItemManager, items: Etebase.CollectionItem[], _deps?: Etebase.CollectionItem[]) => {
return {
colUid,
items: items,
};
}
);
export const itemBatch = createAction( export const itemBatch = createAction(
"ITEM_BATCH", "ITEM_BATCH",
async (_col: Etebase.Collection, itemMgr: Etebase.CollectionItemManager, items: Etebase.CollectionItem[], deps?: Etebase.CollectionItem[]) => { async (_col: Etebase.Collection, itemMgr: Etebase.CollectionItemManager, items: Etebase.CollectionItem[], deps?: Etebase.CollectionItem[]) => {

@ -129,7 +129,10 @@ export const items = handleActions(
} }
return state; return state;
}, },
[actions.itemBatch.toString()]: (state: CacheItemsData, action_: any) => { [combineActions(
actions.itemBatch,
actions.setCacheItemMulti
).toString()]: (state: CacheItemsData, action_: any) => {
// Fails without it for some reason // Fails without it for some reason
const action = action_ as ActionMeta<CacheItem[], { colUid: string, items: Etebase.CollectionItem[] }>; const action = action_ as ActionMeta<CacheItem[], { colUid: string, items: Etebase.CollectionItem[] }>;
if (action.payload !== undefined) { if (action.payload !== undefined) {

@ -6,7 +6,7 @@ import * as Etebase from "etebase";
import { store, StoreState } from "../store"; import { store, StoreState } from "../store";
import { credentialsSelector } from "../credentials"; import { credentialsSelector } from "../credentials";
import { setSyncCollection, setSyncGeneral, setCacheItem, setCacheCollection, unsetCacheCollection, unsetCacheItem } from "../store/actions"; import { setSyncCollection, setSyncGeneral, setCacheCollection, unsetCacheCollection, setCacheItemMulti } from "../store/actions";
const cachedSyncManager = new Map<string, SyncManager>(); const cachedSyncManager = new Map<string, SyncManager>();
export class SyncManager { export class SyncManager {
@ -44,13 +44,7 @@ export class SyncManager {
let done = false; let done = false;
while (!done) { while (!done) {
const items = await itemMgr.list({ stoken, limit }); const items = await itemMgr.list({ stoken, limit });
for (const item of items.data) { store.dispatch(setCacheItemMulti(col.uid, itemMgr, items.data));
if (item.isDeleted) {
store.dispatch(unsetCacheItem(col.uid, itemMgr, item.uid));
} else {
store.dispatch(setCacheItem(col, itemMgr, item));
}
}
done = items.done; done = items.done;
stoken = items.stoken; stoken = items.stoken;
} }

Loading…
Cancel
Save