work around load() bug

This commit is contained in:
Daniel Lugo 2020-07-23 13:01:43 -04:00
parent ef31b0c375
commit bb1138579d
3 changed files with 87 additions and 7 deletions

View file

@ -9,6 +9,7 @@ const Utils = require('../utils')
const Wall = require('./wall') const Wall = require('./wall')
const Feed = require('./feed') const Feed = require('./feed')
const User = require('./user') const User = require('./user')
const { size } = require('lodash')
/** /**
* @param {string} pub * @param {string} pub
@ -51,7 +52,18 @@ exports.userToIncomingID = async pub => {
const getMyUser = async () => { const getMyUser = async () => {
const oldProfile = await Utils.tryAndWait( const oldProfile = await Utils.tryAndWait(
(_, user) => new Promise(res => user.get(Key.PROFILE).load(res)), (_, user) => new Promise(res => user.get(Key.PROFILE).load(res)),
v => typeof v !== 'object' v => {
if (typeof v !== 'object') {
return true
}
if (v === null) {
return true
}
// load sometimes returns an empty set on the first try
return size(v) === 0
}
) )
const bio = await Utils.tryAndWait( const bio = await Utils.tryAndWait(

View file

@ -2,6 +2,7 @@
* @format * @format
*/ */
const Common = require('shock-common') const Common = require('shock-common')
const size = require('lodash/size')
const Key = require('../key') const Key = require('../key')
const Utils = require('../utils') const Utils = require('../utils')
@ -72,7 +73,18 @@ module.exports.getAnUser = getAnUser
const getMyUser = async () => { const getMyUser = async () => {
const oldProfile = await Utils.tryAndWait( const oldProfile = await Utils.tryAndWait(
(_, user) => new Promise(res => user.get(Key.PROFILE).load(res)), (_, user) => new Promise(res => user.get(Key.PROFILE).load(res)),
v => typeof v !== 'object' v => {
if (typeof v !== 'object') {
return true
}
if (v === null) {
return true
}
// load sometimes returns an empty set on the first try
return size(v) === 0
}
) )
const bio = await Utils.tryAndWait( const bio = await Utils.tryAndWait(

View file

@ -13,6 +13,7 @@ const responseTime = require("response-time");
const uuid = require("uuid/v4"); const uuid = require("uuid/v4");
const Common = require('shock-common') const Common = require('shock-common')
const isARealUsableNumber = require('lodash/isFinite') const isARealUsableNumber = require('lodash/isFinite')
const size = require('lodash/size')
const getListPage = require("../utils/paginate"); const getListPage = require("../utils/paginate");
const auth = require("../services/auth/auth"); const auth = require("../services/auth/auth");
@ -2249,7 +2250,18 @@ module.exports = async (
u.get(GunKey.USER_TO_INCOMING).load(data => { u.get(GunKey.USER_TO_INCOMING).load(data => {
res(data) res(data)
}) })
})) }), v => {
if (typeof v !== 'object') {
return true
}
if (v === null) {
return true
}
// load sometimes returns an empty set on the first try
return size(v) === 0
})
return res.status(200).json({ return res.status(200).json({
data data
@ -2269,7 +2281,18 @@ module.exports = async (
u.get(GunKey.RECIPIENT_TO_OUTGOING).load(data => { u.get(GunKey.RECIPIENT_TO_OUTGOING).load(data => {
res(data) res(data)
}) })
})) }), v => {
if (typeof v !== 'object') {
return true
}
if (v === null) {
return true
}
// load sometimes returns an empty set on the first try
return size(v) === 0
})
return res.status(200).json({ return res.status(200).json({
data data
@ -2289,7 +2312,18 @@ module.exports = async (
u.get(GunKey.OUTGOINGS).load(data => { u.get(GunKey.OUTGOINGS).load(data => {
res(data) res(data)
}) })
})) }), v => {
if (typeof v !== 'object') {
return true
}
if (v === null) {
return true
}
// load sometimes returns an empty set on the first try
return size(v) === 0
})
return res.status(200).json({ return res.status(200).json({
data data
@ -2328,7 +2362,18 @@ module.exports = async (
res(data) res(data)
}) })
}) })
) , v => {
if (typeof v !== 'object') {
return true
}
if (v === null) {
return true
}
// load sometimes returns an empty set on the first try
return size(v) === 0
})
return res.status(200).json({ return res.status(200).json({
data data
@ -2350,7 +2395,18 @@ module.exports = async (
res(data) res(data)
}) })
}) })
) , v => {
if (typeof v !== 'object') {
return true
}
if (v === null) {
return true
}
// load sometimes returns an empty set on the first try
return size(v) === 0
})
return res.status(200).json({ return res.status(200).json({
data data