Commit 605b1b40 authored by Guy Thouret's avatar Guy Thouret

(fix) Move the increment and test of offset inside the async pipe in FeaturedContentService - #2190

1 merge request!629WIP: Fix duplicate boost posts appearing in newfeed
Pipeline #94111035 running with stages
......@@ -4,10 +4,8 @@ import { FeedsService } from '../../services/feeds.service';
@Injectable()
export class FeaturedContentService {
offset = -1;
offset = 0;
maximumOffset = 0;
maximumEmptyFetch = 5;
emptyFetchCount = 0;
feedLength = 0;
constructor(protected feedsService: FeedsService) {
......@@ -16,10 +14,6 @@ export class FeaturedContentService {
console.log('BOOST feed.length: ' + feed.length);
this.feedLength = feed.length;
this.maximumOffset = this.feedLength - 1;
if (this.feedLength > 0) {
this.emptyFetchCount = 0;
}
});
this.feedsService
......@@ -30,49 +24,22 @@ export class FeaturedContentService {
}
async fetch() {
if (this.feedReset()) {
this.fetchNextFeed();
}
this.retryFetchIfNoFeedData();
return this.entityFromFeed();
}
protected feedReset(): boolean {
if (this.offset++ >= this.maximumOffset) {
this.offset = 0;
return true;
}
return false;
}
protected retryFetchIfNoFeedData() {
while (
this.feedLength === 0 &&
this.emptyFetchCount < this.maximumEmptyFetch
) {
/** TODO: Remove Debug Line */
console.log('BOOST retry fetch - no feed data');
this.emptyFetchCount++;
this.feedsService.fetch();
}
}
protected async entityFromFeed() {
/** TODO: Remove debug line */
console.log('BOOST featuredContentService.offset : ' + this.offset);
return await this.feedsService.feed
.pipe(
filter(item => item.length > 0),
first(),
mergeMap(feed => feed),
filter(entities => entities.length > 0),
mergeMap(feed => feed), // Convert feed array to stream
skip(this.offset),
take(1),
switchMap(async entity => {
if (!entity) {
return false;
} else {
if (this.offset++ >= this.maximumOffset) {
this.offset = 0;
this.fetchNextFeed();
}
return await entity.pipe(first()).toPromise();
}
return await entity.pipe(first()).toPromise();
})
)
.toPromise();
......
Please register or to comment