simpler retry logic
This commit is contained in:
parent
7df73ca49e
commit
a48362c45b
1 changed files with 30 additions and 16 deletions
|
|
@ -2,6 +2,9 @@
|
|||
* @format
|
||||
*/
|
||||
const Common = require('shock-common')
|
||||
const pickBy = require('lodash/pickBy')
|
||||
const size = require('lodash/size')
|
||||
const mapValues = require('lodash/mapValues')
|
||||
|
||||
const Utils = require('../utils')
|
||||
const Key = require('../key')
|
||||
|
|
@ -95,6 +98,11 @@ const getWallPage = async (page, publicKey) => {
|
|||
return empty
|
||||
}
|
||||
|
||||
/**
|
||||
* We just use it so Common.Schema.isWallPage passes.
|
||||
*/
|
||||
const mockUser = await User.getMyUser()
|
||||
|
||||
/**
|
||||
* @type {Common.SchemaTypes.WallPage}
|
||||
*/
|
||||
|
|
@ -129,32 +137,38 @@ const getWallPage = async (page, publicKey) => {
|
|||
})
|
||||
},
|
||||
maybePage => {
|
||||
if (typeof maybePage !== 'object' || maybePage === null) {
|
||||
// sometimes load() returns an empty object on the first call
|
||||
if (size(/** @type {any} */ (maybePage)) === 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
const clean = {
|
||||
...maybePage
|
||||
const page = /** @type {Common.Schema.WallPage} */ (maybePage)
|
||||
|
||||
if (typeof page.count !== 'number') {
|
||||
return true
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
for (const [key, post] of Object.entries(clean.posts)) {
|
||||
// delete unsuccessful writes
|
||||
if (post === null) {
|
||||
// @ts-ignore
|
||||
delete clean.posts[key]
|
||||
} else {
|
||||
post.id = key
|
||||
}
|
||||
}
|
||||
// removes 'unused' initializer and aborted writes
|
||||
page.posts = pickBy(page.posts, v => v !== null)
|
||||
|
||||
// .load() sometimes doesn't load all data on first call
|
||||
// @ts-ignore
|
||||
if (Object.keys(clean.posts).length === 0) {
|
||||
if (size(page.posts) === 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
return !Common.Schema.isWallPage(clean)
|
||||
// Give ids based on keys
|
||||
page.posts = mapValues(page.posts, (v, k) => ({
|
||||
...v,
|
||||
id: k
|
||||
}))
|
||||
|
||||
page.posts = mapValues(page.posts, v => ({
|
||||
...v,
|
||||
// isWallPage() would otherwise not pass
|
||||
author: mockUser
|
||||
}))
|
||||
|
||||
return !Common.Schema.isWallPage(page)
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue