Skip to content

Commit

Permalink
Filtered out duplicated followers
Browse files Browse the repository at this point in the history
refs [AP-368](https://linear.app/tryghost/issue/AP-368/filter-out-duplicated-followers)

Added filtering to the followers & followers count dipatchers to remove any
duplicate followers from the list. This is a temporary fix until we update the
database to remove the duplicates
  • Loading branch information
mike182uk committed Aug 22, 2024
1 parent adf2431 commit fd5e068
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/dispatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,20 @@ export async function followersDispatcher(
) {
console.log('Followers Dispatcher');
let items: Recipient[] = [];
const fullResults = await ctx.data.db.get<any[]>(['followers', 'expanded']);
const fullResults = (await ctx.data.db.get<any[]>(['followers', 'expanded']) ?? [])
.filter((v, i, results) => {
// Remove duplicates
return results.findIndex((r) => r.id === v.id) === i;
});
if (fullResults) {
items = fullResults.map(convertJsonLdToRecipient)
} else {
const results = (await ctx.data.db.get<string[]>(['followers'])) || [];
const results = [
// Remove duplicates
...new Set(
(await ctx.data.db.get<string[]>(['followers'])) || []
)
];
const actors = items = (await Promise.all(results.map((result) => lookupActor(ctx, result))))
.filter((item): item is Actor => isActor(item))
const toStore = await Promise.all(actors.map(actor => actor.toJsonLd() as any));
Expand All @@ -299,7 +308,12 @@ export async function followersCounter(
ctx: RequestContext<ContextData>,
handle: string,
) {
const results = (await ctx.data.db.get<string[]>(['followers'])) || [];
const results = [
// Remove duplicates
...new Set(
(await ctx.data.db.get<string[]>(['followers'])) || []
)
];
return results.length;
}

Expand Down

0 comments on commit fd5e068

Please sign in to comment.