Skip to content

Commit

Permalink
reduce contribution collection for pack listings
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Jan 17, 2024
1 parent 1360bbd commit 48cdbb5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/v2/interfaces/contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface ContributionsRepository {
updateContribution(id: string, params: ContributionCreationParams): Promise<Contribution>;
getByDateRange(begin: string, ends: string): Promise<Contributions>;
getAuthors(): Promise<ContributionsAuthors>;
getPacks(): FaithfulPack[];
getPacks(): Promise<FaithfulPack[]>;
searchByIdAndPacks(
textureIDs: Array<string>,
packs: Array<string>,
Expand Down
15 changes: 12 additions & 3 deletions src/v2/repository/firestorm/contributions.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Contributions,
ContributionsRepository,
ContributionsAuthors,
FaithfulPacksArr,
FaithfulPack,
} from "../../interfaces";
import { contributions, users } from "../../firestorm";
Expand All @@ -14,8 +13,18 @@ export default class ContributionFirestormRepository implements ContributionsRep
return contributions.get(id);
}

getPacks(): FaithfulPack[] {
return [...FaithfulPacksArr] as FaithfulPack[];
getPacks(): Promise<FaithfulPack[]> {
return contributions.select({ fields: ["pack"] }).then((res: Contributions) =>
(
Object.values(res).reduce(
(acc: Array<string>, cur: any) => [...acc, cur.pack],
[],
) as Array<FaithfulPack>
)
.flat()
.filter((e, i, a) => a.indexOf(e) === i)
.sort(),
);
}

searchContributionsFrom(authors: Array<string>, packs: Array<string>): Promise<Contributions> {
Expand Down
2 changes: 1 addition & 1 deletion src/v2/repository/firestorm/texture.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default class TextureFirestormRepository implements TextureRepository {
.select({
fields: ["tags"],
})
.then((res: any) =>
.then((res: Textures) =>
(
Object.values(res).reduce(
(acc: Array<string>, cur: any) => [...acc, cur.tags],
Expand Down
2 changes: 1 addition & 1 deletion src/v2/service/contributions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class ContributionService {
});
}

getPacks(): FaithfulPack[] {
getPacks(): Promise<FaithfulPack[]> {
return this.contributionRepo.getPacks();
}

Expand Down

0 comments on commit 48cdbb5

Please sign in to comment.