Improvements to feed assembly to avoid possible state issues (#1318)
* Avoid potential dropped posts due to pruning when checking for latest * Add a sanity check to ensure dup react keys never occur (close #1315)zio/stable
parent
e2f0770b88
commit
5ee754e6f9
|
@ -105,6 +105,7 @@ export class FeedTuner {
|
|||
tune(
|
||||
feed: FeedViewPost[],
|
||||
tunerFns: FeedTunerFn[] = [],
|
||||
{dryRun}: {dryRun: boolean} = {dryRun: false},
|
||||
): FeedViewPostsSlice[] {
|
||||
let slices: FeedViewPostsSlice[] = []
|
||||
|
||||
|
@ -156,9 +157,11 @@ export class FeedTuner {
|
|||
}
|
||||
}
|
||||
|
||||
for (const slice of slices) {
|
||||
for (const item of slice.items) {
|
||||
this.seenUris.add(item.post.uri)
|
||||
if (!dryRun) {
|
||||
for (const slice of slices) {
|
||||
for (const item of slice.items) {
|
||||
this.seenUris.add(item.post.uri)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -277,7 +277,9 @@ export class PostsFeedModel {
|
|||
}
|
||||
const res = await this._getFeed({limit: 1})
|
||||
if (res.data.feed[0]) {
|
||||
const slices = this.tuner.tune(res.data.feed, this.feedTuners)
|
||||
const slices = this.tuner.tune(res.data.feed, this.feedTuners, {
|
||||
dryRun: true,
|
||||
})
|
||||
if (slices[0]) {
|
||||
const sliceModel = new PostsFeedSliceModel(this.rootStore, slices[0])
|
||||
if (sliceModel.moderation.content.filter) {
|
||||
|
@ -374,6 +376,15 @@ export class PostsFeedModel {
|
|||
const toAppend: PostsFeedSliceModel[] = []
|
||||
for (const slice of slices) {
|
||||
const sliceModel = new PostsFeedSliceModel(this.rootStore, slice)
|
||||
const dupTest = (item: PostsFeedSliceModel) =>
|
||||
item._reactKey === sliceModel._reactKey
|
||||
// sanity check
|
||||
// if a duplicate _reactKey passes through, the UI breaks hard
|
||||
if (!replace) {
|
||||
if (this.slices.find(dupTest) || toAppend.find(dupTest)) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
toAppend.push(sliceModel)
|
||||
}
|
||||
runInAction(() => {
|
||||
|
|
Loading…
Reference in New Issue