|
|
@ -268,7 +268,18 @@ export default abstract class CacheMgr { |
|
|
|
const allParents = []; |
|
|
|
const allParents = []; |
|
|
|
// get all parents from children
|
|
|
|
// get all parents from children
|
|
|
|
values.forEach((v) => { |
|
|
|
values.forEach((v) => { |
|
|
|
allParents.push(...this.getParents(v)); |
|
|
|
if (v) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const o = JSON.parse(v); |
|
|
|
|
|
|
|
if (typeof o === 'object') { |
|
|
|
|
|
|
|
allParents.push(...this.getParents(o)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
logger.error( |
|
|
|
|
|
|
|
`${this.context}::getList: Bad value stored for key ${arr[0]} : ${v}`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
// remove duplicates
|
|
|
|
// remove duplicates
|
|
|
|
const uniqueParents = [...new Set(allParents)]; |
|
|
|
const uniqueParents = [...new Set(allParents)]; |
|
|
@ -351,18 +362,18 @@ export default abstract class CacheMgr { |
|
|
|
} |
|
|
|
} |
|
|
|
log(`${this.context}::setList: get key ${getKey}`); |
|
|
|
log(`${this.context}::setList: get key ${getKey}`); |
|
|
|
// get key
|
|
|
|
// get key
|
|
|
|
let value = await this.getRaw(getKey, CacheGetType.TYPE_OBJECT); |
|
|
|
let rawValue = await this.getRaw(getKey, CacheGetType.TYPE_OBJECT); |
|
|
|
if (value) { |
|
|
|
if (rawValue) { |
|
|
|
log(`${this.context}::setList: preparing key ${getKey}`); |
|
|
|
log(`${this.context}::setList: preparing key ${getKey}`); |
|
|
|
// prepare key
|
|
|
|
// prepare key
|
|
|
|
value = this.prepareValue({ |
|
|
|
rawValue = this.prepareValue({ |
|
|
|
value: o, |
|
|
|
value: o, |
|
|
|
parentKeys: this.getParents(value), |
|
|
|
parentKeys: this.getParents(rawValue), |
|
|
|
newKey: listKey, |
|
|
|
newKey: listKey, |
|
|
|
timestamp, |
|
|
|
timestamp, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
value = this.prepareValue({ |
|
|
|
rawValue = this.prepareValue({ |
|
|
|
value: o, |
|
|
|
value: o, |
|
|
|
parentKeys: [listKey], |
|
|
|
parentKeys: [listKey], |
|
|
|
timestamp, |
|
|
|
timestamp, |
|
|
@ -370,7 +381,7 @@ export default abstract class CacheMgr { |
|
|
|
} |
|
|
|
} |
|
|
|
// set key
|
|
|
|
// set key
|
|
|
|
log(`${this.context}::setList: setting key ${getKey}`); |
|
|
|
log(`${this.context}::setList: setting key ${getKey}`); |
|
|
|
await this.set(getKey, value, { |
|
|
|
await this.set(getKey, rawValue, { |
|
|
|
skipPrepare: true, |
|
|
|
skipPrepare: true, |
|
|
|
timestamp, |
|
|
|
timestamp, |
|
|
|
}); |
|
|
|
}); |
|
|
@ -385,7 +396,7 @@ export default abstract class CacheMgr { |
|
|
|
async deepDel(key: string, direction: string): Promise<boolean> { |
|
|
|
async deepDel(key: string, direction: string): Promise<boolean> { |
|
|
|
log(`${this.context}::deepDel: choose direction ${direction}`); |
|
|
|
log(`${this.context}::deepDel: choose direction ${direction}`); |
|
|
|
if (direction === CacheDelDirection.CHILD_TO_PARENT) { |
|
|
|
if (direction === CacheDelDirection.CHILD_TO_PARENT) { |
|
|
|
const childKey = await this.get(key, CacheGetType.TYPE_OBJECT); |
|
|
|
const childKey = await this.getRaw(key, CacheGetType.TYPE_OBJECT); |
|
|
|
// given a child key, delete all keys in corresponding parent lists
|
|
|
|
// given a child key, delete all keys in corresponding parent lists
|
|
|
|
const scopeList = this.getParents(childKey); |
|
|
|
const scopeList = this.getParents(childKey); |
|
|
|
for (const listKey of scopeList) { |
|
|
|
for (const listKey of scopeList) { |
|
|
@ -447,9 +458,9 @@ export default abstract class CacheMgr { |
|
|
|
|
|
|
|
|
|
|
|
log(`${this.context}::appendToList: get key ${key}`); |
|
|
|
log(`${this.context}::appendToList: get key ${key}`); |
|
|
|
// get Get Key
|
|
|
|
// get Get Key
|
|
|
|
const value = await this.get(key, CacheGetType.TYPE_OBJECT); |
|
|
|
const rawValue = await this.getRaw(key, CacheGetType.TYPE_OBJECT); |
|
|
|
log(`${this.context}::appendToList: preparing key ${key}`); |
|
|
|
log(`${this.context}::appendToList: preparing key ${key}`); |
|
|
|
if (!value) { |
|
|
|
if (!rawValue) { |
|
|
|
// FALLBACK: this is to get rid of all keys that would be effected by this (should never happen)
|
|
|
|
// FALLBACK: this is to get rid of all keys that would be effected by this (should never happen)
|
|
|
|
logger.error(`${this.context}::appendToList: value is empty for ${key}`); |
|
|
|
logger.error(`${this.context}::appendToList: value is empty for ${key}`); |
|
|
|
const allParents = []; |
|
|
|
const allParents = []; |
|
|
@ -471,8 +482,8 @@ export default abstract class CacheMgr { |
|
|
|
} |
|
|
|
} |
|
|
|
// prepare Get Key
|
|
|
|
// prepare Get Key
|
|
|
|
const preparedValue = this.prepareValue({ |
|
|
|
const preparedValue = this.prepareValue({ |
|
|
|
value, |
|
|
|
value: rawValue.value ?? rawValue, |
|
|
|
parentKeys: this.getParents(value), |
|
|
|
parentKeys: this.getParents(rawValue), |
|
|
|
newKey: listKey, |
|
|
|
newKey: listKey, |
|
|
|
}); |
|
|
|
}); |
|
|
|
// set Get Key
|
|
|
|
// set Get Key
|
|
|
@ -517,7 +528,9 @@ export default abstract class CacheMgr { |
|
|
|
return []; |
|
|
|
return []; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
logger.error( |
|
|
|
logger.error( |
|
|
|
`${this.context}::getParents: parentKeys not found ${rawValue}`, |
|
|
|
`${this.context}::getParents: parentKeys not found ${JSON.stringify( |
|
|
|
|
|
|
|
rawValue, |
|
|
|
|
|
|
|
)}`,
|
|
|
|
); |
|
|
|
); |
|
|
|
return []; |
|
|
|
return []; |
|
|
|
} |
|
|
|
} |
|
|
|