fixed objectCollection not leaving a journal entry on removal
This commit is contained in:
parent
e0d9a71322
commit
6877008017
2 changed files with 36 additions and 10 deletions
|
|
@ -139,7 +139,7 @@ export const _getRecentData = (cache, live, isTest) => {
|
|||
result.stale = live
|
||||
} else {
|
||||
console.debug(
|
||||
'Different timestamp, figuring out which one is more recent',
|
||||
'Different timestamp or version, figuring out which one is more recent',
|
||||
)
|
||||
if (live._timestamp < cache._timestamp) {
|
||||
result.recent = cache
|
||||
|
|
@ -522,6 +522,7 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
|||
const collection = new Set(get(this.prefsStorage, path))
|
||||
collection.delete(value)
|
||||
set(this.prefsStorage, path, [...collection])
|
||||
|
||||
this.prefsStorage._journal = [
|
||||
...this.prefsStorage._journal,
|
||||
{
|
||||
|
|
@ -535,8 +536,19 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
|||
} else if (path.startsWith('objectCollection')) {
|
||||
const collection = new Set(get(this.prefsStorage, path + '.index'))
|
||||
collection.delete(_key)
|
||||
set(this.prefsStorage, path + '.index', [...collection])
|
||||
const data = get(this.prefsStorage, path + '.data')
|
||||
delete data[_key]
|
||||
|
||||
this.prefsStorage._journal = [
|
||||
...this.prefsStorage._journal,
|
||||
{
|
||||
operation: 'removeFromCollection',
|
||||
path,
|
||||
args: [{ _key }],
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
reorderCollectionPreference({ path, value, movement }) {
|
||||
|
|
@ -579,14 +591,13 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
|||
const live = userData.storage
|
||||
this.raw = live
|
||||
let cache = this.cache
|
||||
if (cache && cache._user !== userData.fqn) {
|
||||
if (cache?._user !== userData.fqn) {
|
||||
console.warn(
|
||||
'Cache belongs to another user! reinitializing local cache!',
|
||||
)
|
||||
cache = null
|
||||
}
|
||||
|
||||
cache = _doMigrations(cache, live)
|
||||
console.log(cache, live)
|
||||
|
||||
let { recent, stale, needUpload } = _getRecentData(cache, live)
|
||||
|
||||
|
|
@ -604,6 +615,9 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
|||
})
|
||||
}
|
||||
|
||||
recent = recent && _doMigrations(recent)
|
||||
stale = stale && _doMigrations(stale)
|
||||
|
||||
if (!needUpload && recent && stale) {
|
||||
console.debug('Checking if data needs merging...')
|
||||
// discarding timestamps and versions
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue