ensure follows gets loaded on first try

This commit is contained in:
Daniel Lugo 2020-08-04 13:30:54 -04:00
parent aa748323e2
commit c0f36d71dd

View file

@ -21,15 +21,25 @@ exports.currentFollows = async () => {
* @type {Record<string, Common.Schema.Follow>} * @type {Record<string, Common.Schema.Follow>}
*/ */
const raw = await Utils.tryAndWait( const raw = await Utils.tryAndWait(
// @ts-ignore (_, user) =>
(_, user) => new Promise(res => user.get(Key.FOLLOWS).load(res)), new Promise(res =>
// @ts-expect-error
user.get(Key.FOLLOWS).load(res)
),
v => { v => {
if (typeof v !== 'object' || v === null) { if (typeof v !== 'object' || v === null) {
return true return true
} }
// load sometimes returns an empty set on the first try // load sometimes returns an empty set on the first try
return size(v) === 0 if (size(v) === 0) {
return true
}
// sometimes it returns empty sub objects
return Object.values(v)
.filter(Common.Schema.isObj)
.some(obj => size(obj) === 0)
} }
) )