From bb1138579d007d426f2823f91b50a3c17541a8c7 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 23 Jul 2020 13:01:43 -0400 Subject: [PATCH] work around load() bug --- services/gunDB/contact-api/getters/index.js | 14 ++++- services/gunDB/contact-api/getters/user.js | 14 ++++- src/routes.js | 66 +++++++++++++++++++-- 3 files changed, 87 insertions(+), 7 deletions(-) diff --git a/services/gunDB/contact-api/getters/index.js b/services/gunDB/contact-api/getters/index.js index 3a82e410..4472ed41 100644 --- a/services/gunDB/contact-api/getters/index.js +++ b/services/gunDB/contact-api/getters/index.js @@ -9,6 +9,7 @@ const Utils = require('../utils') const Wall = require('./wall') const Feed = require('./feed') const User = require('./user') +const { size } = require('lodash') /** * @param {string} pub @@ -51,7 +52,18 @@ exports.userToIncomingID = async pub => { const getMyUser = async () => { const oldProfile = await Utils.tryAndWait( (_, 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( diff --git a/services/gunDB/contact-api/getters/user.js b/services/gunDB/contact-api/getters/user.js index fb8054e1..52d04e72 100644 --- a/services/gunDB/contact-api/getters/user.js +++ b/services/gunDB/contact-api/getters/user.js @@ -2,6 +2,7 @@ * @format */ const Common = require('shock-common') +const size = require('lodash/size') const Key = require('../key') const Utils = require('../utils') @@ -72,7 +73,18 @@ module.exports.getAnUser = getAnUser const getMyUser = async () => { const oldProfile = await Utils.tryAndWait( (_, 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( diff --git a/src/routes.js b/src/routes.js index 15a785b7..dcffb4cc 100644 --- a/src/routes.js +++ b/src/routes.js @@ -13,6 +13,7 @@ const responseTime = require("response-time"); const uuid = require("uuid/v4"); const Common = require('shock-common') const isARealUsableNumber = require('lodash/isFinite') +const size = require('lodash/size') const getListPage = require("../utils/paginate"); const auth = require("../services/auth/auth"); @@ -2249,7 +2250,18 @@ module.exports = async ( u.get(GunKey.USER_TO_INCOMING).load(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({ data @@ -2269,7 +2281,18 @@ module.exports = async ( u.get(GunKey.RECIPIENT_TO_OUTGOING).load(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({ data @@ -2289,7 +2312,18 @@ module.exports = async ( u.get(GunKey.OUTGOINGS).load(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({ data @@ -2328,7 +2362,18 @@ module.exports = async ( 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({ data @@ -2350,7 +2395,18 @@ module.exports = async ( 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({ data