Added mutex to fix duplicated posts

This commit is contained in:
Ariadna 2025-05-10 14:07:37 -04:00
parent c84ff140ca
commit b3e8c7eac1
3 changed files with 179 additions and 57 deletions

View file

@ -13,6 +13,7 @@ import {
WebDidDocumentResolver,
} from "@atcute/identity-resolver";
import { Config } from "../../config";
import { Mutex } from "mutex-ts"
// import { ComAtprotoRepoListRecords.Record } from "@atcute/client/lexicons";
// import { AppBskyFeedPost } from "@atcute/client/lexicons";
// import { AppBskyActorDefs } from "@atcute/client/lexicons";
@ -247,8 +248,11 @@ const filterPostsByDate = (posts: PostsAcc[], cutoffDate: Date) => {
});
return filteredPosts;
};
const postsMutex = new Mutex();
// nightmare function. However it works so I am not touching it
const getNextPosts = async () => {
const release = await postsMutex.obtain();
if (!accountsMetadata.length) {
accountsMetadata = await getAllMetadataFromPds();
}
@ -322,6 +326,8 @@ const getNextPosts = async () => {
}
return new Post(record, account);
});
// release the mutex
release();
return newPosts;
};