Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Aug 1, 2024
1 parent 5761c8f commit b78f8e1
Show file tree
Hide file tree
Showing 11 changed files with 509 additions and 668 deletions.
6 changes: 3 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ model User {
QP Int @default(0)
bank Json @default("{}") @db.Json
collectionLogBank Json @default("{}") @db.JsonB
cl_array Int[] @default([])
blowpipe Json @default("{\"scales\":0,\"dartID\":null,\"dartQuantity\":0}") @db.Json
slayer_unlocks Int[] @default([]) @map("slayer.unlocks")
slayer_blocked_ids Int[] @default([]) @map("slayer.blocked_ids")
Expand Down Expand Up @@ -405,7 +404,6 @@ model User {
store_bitfield Int[] @default([])
// Migrate
farmingPatches_herb Json? @map("farmingPatches.herb") @db.Json
farmingPatches_fruit_tree Json? @map("farmingPatches.fruit tree") @db.Json
farmingPatches_tree Json? @map("farmingPatches.tree") @db.Json
Expand Down Expand Up @@ -437,6 +435,8 @@ model User {
gift_boxes_owned GiftBox[] @relation("gift_boxes_owned")
gift_boxes_created GiftBox[] @relation("gift_boxes_created")
cl_array Int[] @default([])
@@index([id, last_command_date])
@@map("users")
}
Expand Down Expand Up @@ -745,7 +745,7 @@ model UserStats {
creature_scores Json @default("{}")
monster_scores Json @default("{}")
laps_scores Json @default("{}")
sacrificed_bank Json @default("{}")
sacrificed_bank Json @default("{}") @db.JsonB
openable_scores Json @default("{}")
gp_luckypick BigInt @default(0)
Expand Down
8 changes: 6 additions & 2 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ export const BadgesEnum = {
TopSkiller: 9,
TopCollector: 10,
TopMinigame: 11,
SotWTrophy: 12
SotWTrophy: 12,
Slayer: 13,
TopGiveawayer: 14
} as const;

export const badges: { [key: number]: string } = {
Expand All @@ -360,7 +362,9 @@ export const badges: { [key: number]: string } = {
[BadgesEnum.TopSkiller]: Emoji.Skiller,
[BadgesEnum.TopCollector]: Emoji.CollectionLog,
[BadgesEnum.TopMinigame]: Emoji.MinigameIcon,
[BadgesEnum.SotWTrophy]: Emoji.SOTWTrophy
[BadgesEnum.SotWTrophy]: Emoji.SOTWTrophy,
[BadgesEnum.Slayer]: Emoji.Slayer,
[BadgesEnum.TopGiveawayer]: Emoji.SantaHat
};

export const MAX_XP = 200_000_000;
Expand Down
22 changes: 13 additions & 9 deletions src/lib/handleNewCLItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { allCLItems, allCollectionLogsFlat, calcCLDetails } from './data/Collect
import { calculateMastery } from './mastery';
import { calculateOwnCLRanking, roboChimpSyncData } from './roboChimp';

import { RawSQL } from './rawSql';
import { MUserStats } from './structures/MUserStats';
import { fetchCLLeaderboard } from './util/clLeaderboard';
import { insertUserEvent } from './util/userEvents';
Expand Down Expand Up @@ -49,6 +50,10 @@ export async function handleNewCLItems({
await prisma.historicalData.create({ data: await createHistoricalData(user) });
}

if (didGetNewCLItem) {
await prisma.$queryRawUnsafe(RawSQL.updateCLArray(user.id));
}

if (!didGetNewCLItem) return;

const previousCLDetails = calcCLDetails(previousCL);
Expand Down Expand Up @@ -101,15 +106,14 @@ export async function handleNewCLItems({
})}!`
: '';

const nthUser = (
await fetchCLLeaderboard({
ironmenOnly: false,
items: finishedCL.items,
resultLimit: 100_000,
method: 'raw_cl',
userEvents: null
})
).filter(u => u.qty === finishedCL.items.length).length;
const leaderboardUsers = await fetchCLLeaderboard({
ironmenOnly: false,
items: finishedCL.items,
resultLimit: 100_000,
clName: finishedCL.name
});

const nthUser = leaderboardUsers.users.filter(u => u.qty === finishedCL.items.length).length;

const placeStr = nthUser > 100 ? '' : ` They are the ${formatOrdinal(nthUser)} user to finish this CL.`;

Expand Down
11 changes: 11 additions & 0 deletions src/lib/rawSql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Prisma } from '@prisma/client';

const u = Prisma.UserScalarFieldEnum;

export const RawSQL = {
updateCLArray: (userID: string) => `UPDATE users
SET ${u.cl_array} = (
SELECT (ARRAY(SELECT jsonb_object_keys("${u.collectionLogBank}")::int))
)
WHERE ${u.id} = '${userID}';`
};
Loading

0 comments on commit b78f8e1

Please sign in to comment.