fix: preserve other users local sync data
This commit is contained in:
parent
f7756d8936
commit
508e63aca2
|
|
@ -84,8 +84,7 @@ export const useEntryStore = defineStore("entries", {
|
|||
);
|
||||
const pendingOperations = (await db.syncOperations.filter((operation) => operation.syncedAt === null).toArray())
|
||||
.filter((operation) =>
|
||||
(operation.userId ?? operation.payload.updatedBy) === auth.user!.id
|
||||
|| operation.ledgerIds.some((ledgerId) => allowedLedgerIds.has(ledgerId)),
|
||||
(operation.userId ?? operation.payload.updatedBy) === auth.user!.id,
|
||||
);
|
||||
this.pendingEntryIds = [...new Set(pendingOperations.map((operation) => operation.entityId))];
|
||||
this.pendingEntries = [...new Map(
|
||||
|
|
|
|||
|
|
@ -55,22 +55,9 @@ export const useLedgerStore = defineStore("ledgers", {
|
|||
this.ledgers = serverLedgers;
|
||||
|
||||
const allowedIds = new Set(this.ledgers.map((ledger) => ledger.id));
|
||||
const localEntries = await db.entries.toArray();
|
||||
const inaccessibleEntries = localEntries
|
||||
.filter((entry) => entry.ownerId !== auth.user!.id && !entry.ledgerIds.some((ledgerId) => allowedIds.has(ledgerId)))
|
||||
.map((entry) => entry.id);
|
||||
const projectedEntries = localEntries
|
||||
.filter((entry) => entry.ownerId !== auth.user!.id && entry.ledgerIds.some((ledgerId) => !allowedIds.has(ledgerId)))
|
||||
.map((entry) => ({ ...entry, ledgerIds: entry.ledgerIds.filter((ledgerId) => allowedIds.has(ledgerId)) }));
|
||||
const inaccessibleOperations = await db.syncOperations
|
||||
.filter((item) => (item.userId ?? item.payload.updatedBy) !== auth.user!.id)
|
||||
.primaryKeys();
|
||||
await db.transaction("rw", db.ledgers, db.entries, db.syncOperations, async () => {
|
||||
await db.transaction("rw", db.ledgers, async () => {
|
||||
await db.ledgers.clear();
|
||||
if (serverLedgers.length) await db.ledgers.bulkPut(serverLedgers);
|
||||
if (projectedEntries.length) await db.entries.bulkPut(projectedEntries);
|
||||
if (inaccessibleEntries.length) await db.entries.bulkDelete(inaccessibleEntries);
|
||||
if (inaccessibleOperations.length) await db.syncOperations.bulkDelete(inaccessibleOperations);
|
||||
});
|
||||
|
||||
const preferenceId = currentLedgerPreferenceId(auth.user.id);
|
||||
|
|
|
|||
Loading…
Reference in New Issue