fix(collection/redis): rebuidIndexes don't fail on missing items (#651)
Instead of failing when an id refers to a no missing item, simply remove it from the index.
This commit is contained in:
parent
39f4e13915
commit
4f13b32f9a
@ -64,18 +64,24 @@ export default class Redis extends Collection {
|
|||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const idsIndex = `${prefix}_ids`
|
||||||
return asyncMap(indexes, index =>
|
return asyncMap(indexes, index =>
|
||||||
redis.keys(`${prefix}_${index}:*`).then(keys =>
|
redis.keys(`${prefix}_${index}:*`).then(keys =>
|
||||||
keys.length !== 0 && redis.del(keys)
|
keys.length !== 0 && redis.del(keys)
|
||||||
)
|
)
|
||||||
).then(() => asyncMap(redis.smembers(`${prefix}_ids`), id =>
|
).then(() => asyncMap(redis.smembers(idsIndex), id =>
|
||||||
redis.hgetall(`${prefix}:${id}`).then(values =>
|
redis.hgetall(`${prefix}:${id}`).then(values =>
|
||||||
asyncMap(indexes, index => {
|
values == null
|
||||||
const value = values[index]
|
? redis.srem(idsIndex, id) // entry no longer exists
|
||||||
if (value !== undefined) {
|
: asyncMap(indexes, index => {
|
||||||
return redis.sadd(`${prefix}_${index}:${String(value).toLowerCase()}`, id)
|
const value = values[index]
|
||||||
}
|
if (value !== undefined) {
|
||||||
})
|
return redis.sadd(
|
||||||
|
`${prefix}_${index}:${String(value).toLowerCase()}`,
|
||||||
|
id
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user