Skip to content

Commit

Permalink
Fix profile overview command
Browse files Browse the repository at this point in the history
  • Loading branch information
abbyfour committed Sep 1, 2024
1 parent 5d799c2 commit 41276fd
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data/
**/.DS_Store

config.json
ormconfig.json
ormconfig.ts

docker-compose.*.yml
Dockerfile.dev
Expand Down
24 changes: 0 additions & 24 deletions ormconfig.example.json

This file was deleted.

16 changes: 0 additions & 16 deletions ormconfig.ts

This file was deleted.

68 changes: 68 additions & 0 deletions ormconfig.ts.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { DataSource } from "typeorm";
import { AlternateAlbumCover } from "./src/database/entity/AlternateAlbumCover";
import { ArtistCrownBan } from "./src/database/entity/ArtistCrownBan";
import { ArtistRedirect } from "./src/database/entity/ArtistRedirect";
import { ArtistTagCache } from "./src/database/entity/ArtistTagCache";
import { CachedLovedTrack } from "./src/database/entity/CachedLovedTrack";
import { AlbumCard } from "./src/database/entity/cards/AlbumCard";
import { Combo } from "./src/database/entity/Combo";
import { Crown } from "./src/database/entity/Crown";
import { CrownBan } from "./src/database/entity/CrownBan";
import { FishyCatch } from "./src/database/entity/fishy/FishyCatch";
import { FishyProfile } from "./src/database/entity/fishy/FishyProfile";
import { FishyQuest } from "./src/database/entity/fishy/FishyQuest";
import { Friend } from "./src/database/entity/Friend";
import { CommandRun } from "./src/database/entity/meta/CommandRun";
import { CrownEvent } from "./src/database/entity/meta/CrownEvent";
import { Guild } from "./src/database/entity/meta/Guild";
import { NowPlayingConfig } from "./src/database/entity/NowPlayingConfig";
import { Permission } from "./src/database/entity/Permission";
import { Setting } from "./src/database/entity/Setting";
import { SpotifyPlaylistTag } from "./src/database/entity/SpotifyPlaylistTag";
import { TagBan } from "./src/database/entity/TagBan";
import { User } from "./src/database/entity/User";

export const gowonDatabase = new DataSource({
migrationsTableName: "migrations",
type: "postgres",
// Change to localhost to run migrations
host: "host.docker.internal",
port: 5432,
username: "your username here",
password: "your password here",
database: "gowon",
logging: false,
synchronize: false,
name: "default",
migrations: ["src/database/migration/**/*.js"],

entities: [
AlternateAlbumCover,
ArtistCrownBan,
ArtistRedirect,
ArtistTagCache,
CachedLovedTrack,
Combo,
CommandRun,
Crown,
CrownBan,
CrownEvent,
Error,
Guild,
Friend,
NowPlayingConfig,
Permission,
Setting,
SpotifyPlaylistTag,
TagBan,
User,

// Cards
AlbumCard,

// Fishy
FishyCatch,
FishyProfile,
FishyQuest,
],
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@typescript-eslint/parser": "^5.44.0",
"eslint": "^8.28.0",
"jest": "^27.5.1",
"nodemon": "^3.1.4",
"prettier": "^2.8.0",
"ts-jest": "^27.1.3",
"ts-node": "^10.9.2",
Expand Down
3 changes: 2 additions & 1 deletion src/errors/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export class CouldNotFindUserWithUsername extends ClientError {
}
}


export class CommandRequiresBackerError extends ClientError {
constructor(prefix: string) {
super(
Expand All @@ -117,6 +116,8 @@ export class CommandRequiresResyncError extends ClientError {
`${prefix}sync`
)}\` to re-sync your account.`
);
}
}

export class FailedToModifyUserError extends ServerError {
constructor() {
Expand Down
27 changes: 8 additions & 19 deletions src/lib/calculators/ProfileStatsCalculator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { differenceInDays } from "date-fns";
import gql from "graphql-tag";
import { log } from "mathjs";
import { CrownRankResponse } from "../../database/entity/Crown";
import { LogicError } from "../../errors/errors";
Expand All @@ -17,8 +16,7 @@ import {
} from "../../services/LastFM/converters/TopTypes";
import { ServiceRegistry } from "../../services/ServicesRegistry";
import { CrownsService } from "../../services/dbservices/crowns/CrownsService";
import { MirrorballService } from "../../services/mirrorball/MirrorballService";
import { MirrorballPageInfo } from "../../services/mirrorball/MirrorballTypes";
import { LilacTagsService } from "../../services/lilac/LilacTagsService";
import { GowonContext } from "../context/Context";
import { DateRange } from "../timeAndDate/DateRange";
import { displayDate, displayNumber } from "../ui/displays";
Expand Down Expand Up @@ -49,7 +47,7 @@ export class ProfileStatsCalculator {

private lastFMService = ServiceRegistry.get(LastFMService);
private crownsService = ServiceRegistry.get(CrownsService);
private mirrorballService = ServiceRegistry.get(MirrorballService);
private lilacTagsService = ServiceRegistry.get(LilacTagsService);

constructor(
private ctx: GowonContext,
Expand Down Expand Up @@ -458,22 +456,13 @@ export class ProfileStatsCalculator {

async uniqueTags(): Promise<Stat> {
const topArtists = await this.topArtists();
const query = gql`
query tags($artists: [ArtistInput!]!) {
tags(settings: { artists: $artists }, requireTagsForMissing: true) {
pageInfo {
recordCount
}
}
}
`;

const artists = topArtists.artists.map((a) => ({ name: a.name }));
const artistNames = topArtists.artists.map((a) => ({ name: a.name }));

const response = await this.mirrorballService.query<{
tags: { pageInfo: MirrorballPageInfo };
}>(this.ctx, query, { artists });
const response = await this.lilacTagsService.list(this.ctx, {
artists: artistNames,
fetchTagsForMissing: true,
});

return new Stat(response.tags.pageInfo.recordCount);
return new Stat(response.pagination.totalItems);
}
}
2 changes: 1 addition & 1 deletion src/services/lilac/LilacAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { lilacClient } from "../../lib/Lilac/client";
import { BaseService } from "../BaseService";

export class LilacAPIService extends BaseService {
protected async query<R, V extends OperationVariables>(
public async query<R, V extends OperationVariables>(
ctx: GowonContext,
query: DocumentNode,
variables?: V,
Expand Down
7 changes: 7 additions & 0 deletions src/services/lilac/LilacTagsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ export class LilacTagsService extends LilacAPIService {
name
occurrences
}
pagination {
totalItems
currentPage
totalPages
perPage
}
}
}
`;
Expand Down
Loading

0 comments on commit 41276fd

Please sign in to comment.