My current issue involves a growing array each time I submit a post. It seems like the problem lies within the second observable where the user object gets updated with a new timestamp after each post submission.
I have attempted to prevent duplicate entries in the array by checking if the post already exists inside the observable, but this approach doesn't seem to be effective.
fetchPosts(url: string) {
switch (url) {
case '/timeline/top':
this.postsService.fetchAllPosts(this.selectedArea)
.subscribe(posts => {
let container = new Array<PostContainer>();
for (let post of posts) {
this.getUserEquippedItems(post.username).subscribe(x => {
try {
if (container.indexOf(new PostContainer(post, x[0].equippedItems)) === -1) {
container.push(new PostContainer(post, x[0].equippedItems));
}
console.log( container); // encountering exponential growth after each submitted post
} catch (ex) { }
}
);
}
this.postContainers = container; // postContainers is the array being iterated over in the frontend.
});
break;
}
}