Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt fixes #5726

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
test:
name: Node v${{ matrix.node_version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 5
timeout-minutes: 10
strategy:
matrix:
node_version: [18.12.0, 20]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
test:
name: Node v${{ matrix.node_version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 5
timeout-minutes: 10
strategy:
matrix:
node_version: [18.12.0, 20]
Expand Down
6 changes: 3 additions & 3 deletions src/lib/addXP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

const skillsVals = Object.values(Skills);
const maxFilter = skillsVals.map(s => `"skills.${s.id}" >= ${LEVEL_99_XP}`).join(' AND ');
const makeQuery = (ironman: boolean) => `SELECT count(id)
const makeQuery = (ironman: boolean) => `SELECT count(id)::int
FROM users
WHERE ${maxFilter}
${ironman ? 'AND "minion.ironman" = true' : ''};`;
Expand Down Expand Up @@ -52,7 +52,7 @@

const name = toTitleCase(params.skillName);

const skill = Object.values(Skills).find(skill => skill.id === params.skillName)!;

Check warning on line 55 in src/lib/addXP.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

'skill' is already declared in the upper scope on line 55 column 8

Check warning on line 55 in src/lib/addXP.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

'skill' is already declared in the upper scope on line 55 column 8

const newXP = Math.min(MAX_XP, currentXP + params.amount);
const totalXPAdded = newXP - currentXP;
Expand Down Expand Up @@ -111,7 +111,7 @@
{
count: string;
}[]
>(`SELECT COUNT(*) FROM users WHERE "skills.${params.skillName}" >= ${LEVEL_99_XP};`);
>(`SELECT COUNT(*)::int FROM users WHERE "skills.${params.skillName}" >= ${LEVEL_99_XP};`);

let str = `${skill.emoji} **${user.badgedUsername}'s** minion, ${
user.minionName
Expand All @@ -125,7 +125,7 @@
count: string;
}[]
>(
`SELECT COUNT(*) FROM users WHERE "minion.ironman" = true AND "skills.${params.skillName}" >= ${LEVEL_99_XP};`
`SELECT COUNT(*)::int FROM users WHERE "minion.ironman" = true AND "skills.${params.skillName}" >= ${LEVEL_99_XP};`
);
str += ` They are the ${formatOrdinal(parseInt(ironmenWith.count) + 1)} Ironman to get 99.`;
}
Expand All @@ -149,7 +149,7 @@

if (currentTotalLevel < MAX_TOTAL_LEVEL && user.totalLevel >= MAX_TOTAL_LEVEL) {
str += '\n\n**Congratulations, your minion has reached the maximum total level!**\n\n';
onMax(user);

Check warning on line 152 in src/lib/addXP.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 152 in src/lib/addXP.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
} else if (currentLevel !== newLevel) {
str += params.minimal
? `(Levelled up to ${newLevel})`
Expand Down
8 changes: 4 additions & 4 deletions src/lib/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
const [numberOfMinions, totalSacrificed, numberOfIronmen, totalGP] = (
await Promise.all(
[
'SELECT COUNT(*) FROM users WHERE "minion.hasBought" = true;',
'SELECT SUM ("sacrificedValue") AS count FROM users;',
'SELECT COUNT(*) FROM users WHERE "minion.ironman" = true;',
'SELECT SUM ("GP") AS count FROM users;'
'SELECT COUNT(*)::int FROM users WHERE "minion.hasBought" = true;',
'SELECT SUM("sacrificedValue")::int AS count FROM users;',
'SELECT COUNT(*)::int FROM users WHERE "minion.ironman" = true;',
'SELECT SUM("GP") AS count FROM users;'
].map(query => prisma.$queryRawUnsafe(query))
)
).map((result: any) => parseInt(result[0].count)) as number[];
Expand Down Expand Up @@ -73,7 +73,7 @@
await prisma.analytic.create({
data: {
guildsCount: globalClient.guilds.cache.size,
membersCount: globalClient.guilds.cache.reduce((acc, curr) => (acc += curr.memberCount || 0), 0),

Check warning on line 76 in src/lib/analytics.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

Unexpected number value in conditional. An explicit zero/NaN check is required

Check warning on line 76 in src/lib/analytics.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

Unexpected number value in conditional. An explicit zero/NaN check is required
timestamp: Math.floor(Date.now() / 1000),
clueTasksCount: taskCounts.Clue,
minigameTasksCount: taskCounts.Minigame,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/roboChimp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

export type RobochimpUser = User;

global.roboChimpClient = global.roboChimpClient || new PrismaClient();

Check warning on line 24 in src/lib/roboChimp.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

Unexpected object value in conditional. The condition is always true

Check warning on line 24 in src/lib/roboChimp.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

Unexpected object value in conditional. The condition is always true

export async function getRandomTriviaQuestions(): Promise<TriviaQuestion[]> {
const random: TriviaQuestion[] = await roboChimpClient.$queryRaw`SELECT id, question, answers
Expand Down Expand Up @@ -83,7 +83,7 @@

export async function calculateOwnCLRanking(userID: string) {
const clPercentRank = (
await roboChimpClient.$queryRaw<{ count: number }[]>`SELECT COUNT(*)
await roboChimpClient.$queryRaw<{ count: number }[]>`SELECT COUNT(*)::int
FROM public.user
WHERE osb_cl_percent >= (SELECT osb_cl_percent FROM public.user WHERE id = ${BigInt(userID)});`
)[0].count;
Expand Down
12 changes: 7 additions & 5 deletions src/lib/rolesTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import { ItemBank } from './types';

function addToUserMap(userMap: Record<string, string[]>, id: string, reason: string) {
if (!userMap[id]) userMap[id] = [];

Check warning on line 17 in src/lib/rolesTask.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

Unexpected object value in conditional. The condition is always true

Check warning on line 17 in src/lib/rolesTask.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

Unexpected object value in conditional. The condition is always true
userMap[id].push(reason);
}

Expand All @@ -24,7 +24,7 @@

for (const cl of collections) {
const items = getCollectionItems(cl);
if (!items || items.length === 0) {

Check warning on line 27 in src/lib/rolesTask.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

Unexpected object value in conditional. The condition is always true

Check warning on line 27 in src/lib/rolesTask.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

Unexpected object value in conditional. The condition is always true
throw new Error(`${cl} isn't a valid CL.`);
}
}
Expand All @@ -44,7 +44,7 @@
const mostSlayerTasksDoneQuery = `SELECT user_id::text as id, 'Most Tasks' as desc
FROM slayer_tasks
GROUP BY user_id
ORDER BY count(user_id) DESC
ORDER BY count(user_id)::int DESC
LIMIT 1;`;

async function addRoles({
Expand Down Expand Up @@ -138,7 +138,7 @@

// Top Skillers
async function topSkillers() {
const topSkillers = (

Check warning on line 141 in src/lib/rolesTask.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

'topSkillers' is already declared in the upper scope on line 140 column 17

Check warning on line 141 in src/lib/rolesTask.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

'topSkillers' is already declared in the upper scope on line 140 column 17
await Promise.all([
...skillVals.map(s =>
q<
Expand Down Expand Up @@ -212,7 +212,7 @@
await Promise.all(
collections.map(async clName => {
const items = getCollectionItems(clName);
if (!items || items.length === 0) {

Check warning on line 215 in src/lib/rolesTask.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

Unexpected object value in conditional. The condition is always true

Check warning on line 215 in src/lib/rolesTask.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

Unexpected object value in conditional. The condition is always true
logError(`${clName} collection log doesnt exist`);
return [];
}
Expand All @@ -224,10 +224,10 @@

const [users, ironUsers] = await Promise.all([
q<any>(generateQuery(items, false, 1))
.then(i => i.filter((i: any) => i.qty > 0) as any[])

Check warning on line 227 in src/lib/rolesTask.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

'i' is already declared in the upper scope on line 227 column 14

Check warning on line 227 in src/lib/rolesTask.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

'i' is already declared in the upper scope on line 227 column 14
.catch(handleErr),
q<any>(generateQuery(items, true, 1))
.then(i => i.filter((i: any) => i.qty > 0) as any[])

Check warning on line 230 in src/lib/rolesTask.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

'i' is already declared in the upper scope on line 230 column 14

Check warning on line 230 in src/lib/rolesTask.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

'i' is already declared in the upper scope on line 230 column 14
.catch(handleErr)
]);

Expand Down Expand Up @@ -287,12 +287,12 @@
addToUserMap(userMap, mostValueIronman[0].id, 'Rank 1 Ironman Sacrificed Value');

const mostUniques = await q<any[]>(`SELECT u.id, u.sacbanklength FROM (
SELECT (SELECT COUNT(*) FROM JSONB_OBJECT_KEYS("sacrificed_bank")) sacbanklength, user_id::text as id FROM user_stats
SELECT (SELECT COUNT(*)::int FROM JSONB_OBJECT_KEYS("sacrificed_bank")) sacbanklength, user_id::text as id FROM user_stats
) u
ORDER BY u.sacbanklength DESC LIMIT 1;`);

const mostUniquesIron = await q<any[]>(`SELECT u.id, u.sacbanklength FROM (
SELECT (SELECT COUNT(*) FROM JSONB_OBJECT_KEYS("sacrificed_bank")) sacbanklength, user_id::text as id FROM user_stats
SELECT (SELECT COUNT(*)::int FROM JSONB_OBJECT_KEYS("sacrificed_bank")) sacbanklength, user_id::text as id FROM user_stats
INNER JOIN users ON "user_stats"."user_id"::text = "users"."id"
WHERE "users"."minion.ironman" = true
) u
Expand Down Expand Up @@ -388,7 +388,7 @@
FROM activity
WHERE type = 'Farming'
GROUP BY user_id
ORDER BY count(user_id) DESC
ORDER BY count(user_id)::int DESC
LIMIT 2;`,
`SELECT user_id::text as id, 'Top 2 Tithe Farm' as desc
FROM user_stats
Expand Down Expand Up @@ -445,7 +445,9 @@
'982989775399174184',
'346304390858145792'
];
const res = await prisma.$queryRaw<{ user_id: string; qty: number }[]>`SELECT user_id, COUNT(user_id) AS qty
const res = await prisma.$queryRaw<
{ user_id: string; qty: number }[]
>`SELECT user_id, COUNT(user_id)::int AS qty
FROM giveaway
WHERE channel_id IN (${Prisma.join(GIVEAWAY_CHANNELS)})
AND user_id NOT IN ('157797566833098752')
Expand Down
2 changes: 1 addition & 1 deletion src/lib/settings/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function convertStoredActivityToFlatActivity(activity: Activity): Activit
* ⚠️ Uses queryRawUnsafe
*/
export async function countUsersWithItemInCl(itemID: number, ironmenOnly: boolean) {
const query = `SELECT COUNT(id)
const query = `SELECT COUNT(id)::int
FROM users
WHERE ("collectionLogBank"->>'${itemID}') IS NOT NULL
AND ("collectionLogBank"->>'${itemID}')::int >= 1
Expand Down
2 changes: 1 addition & 1 deletion src/lib/slayer/slayerUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export function filterLootReplace(myBank: Bank, myLoot: Bank) {

export async function getSlayerTaskStats(userID: string) {
const result: { monster_id: number; total_quantity: number; qty: number }[] =
await prisma.$queryRaw`SELECT monster_id, SUM(quantity) AS total_quantity, COUNT(monster_id) AS qty
await prisma.$queryRaw`SELECT monster_id, SUM(quantity)::int AS total_quantity, COUNT(monster_id)::int AS qty
FROM slayer_tasks
WHERE user_id = ${userID}
AND quantity_remaining = 0
Expand Down
16 changes: 8 additions & 8 deletions src/mahoji/commands/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async function unsafeEval({ userID, code }: { userID: string; code: string }) {
async function allEquippedPets() {
const pets = await prisma.$queryRawUnsafe<
{ pet: number; qty: number }[]
>(`SELECT "minion.equippedPet" AS pet, COUNT("minion.equippedPet") AS qty
>(`SELECT "minion.equippedPet" AS pet, COUNT("minion.equippedPet")::int AS qty
FROM users
WHERE "minion.equippedPet" IS NOT NULL
GROUP BY "minion.equippedPet"
Expand Down Expand Up @@ -289,7 +289,7 @@ AND ("gear.melee" IS NOT NULL OR
>(`SELECT (blowpipe->>'scales')::int AS scales, (blowpipe->>'dartID')::int AS dart, (blowpipe->>'dartQuantity')::int AS qty
FROM users
WHERE blowpipe iS NOT NULL and (blowpipe->>'dartQuantity')::int != 0;`),
prisma.$queryRawUnsafe<{ sum: number }[]>('SELECT SUM("GP") FROM users;'),
prisma.$queryRawUnsafe<{ sum: number }[]>('SELECT SUM("GP")::int FROM users;'),
prisma.$queryRawUnsafe<{ banks: ItemBank }[]>(`SELECT
json_object_agg(itemID, itemQTY)::jsonb as banks
from (
Expand Down Expand Up @@ -329,7 +329,7 @@ WHERE blowpipe iS NOT NULL and (blowpipe->>'dartQuantity')::int != 0;`),
name: 'Most Active',
run: async () => {
const res = await prisma.$queryRawUnsafe<{ num: number; username: string }[]>(`
SELECT sum(duration) as num, "new_user"."username", user_id
SELECT sum(duration)::int as num, "new_user"."username", user_id
FROM activity
INNER JOIN "new_users" "new_user" on "new_user"."id" = "activity"."user_id"::text
WHERE start_date > now() - interval '2 days'
Expand Down Expand Up @@ -409,11 +409,11 @@ The next buy limit reset is at: ${buyLimitInterval.nextResetStr}, it resets ever
run: async () => {
const result = await prisma.$queryRawUnsafe<{ item_id: string; total_gp_spent: number }[]>(`SELECT
key AS item_id,
sum((cost_gp / total_items) * value::integer) AS total_gp_spent
sum((cost_gp / total_items) * value::integer)::int AS total_gp_spent
FROM
buy_command_transaction,
json_each_text(loot_bank),
(SELECT id, sum(value::integer) as total_items FROM buy_command_transaction, json_each_text(loot_bank) GROUP BY id) subquery
(SELECT id, sum(value::integer)::int as total_items FROM buy_command_transaction, json_each_text(loot_bank) GROUP BY id) subquery
WHERE
buy_command_transaction.id = subquery.id
GROUP BY
Expand Down Expand Up @@ -441,7 +441,7 @@ LIMIT
run: async () => {
const result = await prisma.$queryRawUnsafe<
{ item_id: number; gp: number }[]
>(`select item_id, sum(gp_received) as gp
>(`select item_id, sum(gp_received)::int as gp
from bot_item_sell
group by item_id
order by gp desc
Expand All @@ -450,7 +450,7 @@ limit 80;

const totalGPGivenOut = await prisma.$queryRawUnsafe<
{ total_gp_given_out: number }[]
>(`select sum(gp_received) as total_gp_given_out
>(`select sum(gp_received)::int as total_gp_given_out
from bot_item_sell;`);

return {
Expand Down Expand Up @@ -479,7 +479,7 @@ from bot_item_sell;`);
name: 'Max G.E Slot users',
run: async () => {
const res = await prisma.$queryRawUnsafe<{ user_id: string; slots_used: number }[]>(`
SELECT user_id, COUNT(*) AS slots_used
SELECT user_id, COUNT(*)::int AS slots_used
FROM ge_listing
WHERE cancelled_at IS NULL AND fulfilled_at IS NULL
GROUP BY user_id
Expand Down
2 changes: 1 addition & 1 deletion src/mahoji/commands/ge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ The next buy limit reset is at: ${GrandExchange.getInterval().nextResetStr}, it
>(`SELECT
DATE_TRUNC('week', sellTransactions.created_at) AS week,
AVG(sellTransactions.price_per_item_before_tax) AS average_price_per_item_before_tax,
SUM(sellTransactions.quantity_bought) AS total_quantity_bought
SUM(sellTransactions.quantity_bought)::int AS total_quantity_bought
FROM
ge_listing
INNER JOIN
Expand Down
2 changes: 1 addition & 1 deletion src/mahoji/commands/leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async function sacrificeLb(
const mostUniques: { id: string; sacbanklength: number }[] = await prisma.$queryRawUnsafe(
`SELECT u.user_id::text AS id, u.sacbanklength
FROM (
SELECT (SELECT COUNT(*) FROM JSONB_OBJECT_KEYS(sacrificed_bank)) sacbanklength, user_id FROM user_stats
SELECT (SELECT COUNT(*)::int FROM JSONB_OBJECT_KEYS(sacrificed_bank)) sacbanklength, user_id FROM user_stats
${ironmanOnly ? 'INNER JOIN users ON users.id::bigint = user_stats.user_id WHERE "minion.ironman" = true' : ''}
) u
ORDER BY u.sacbanklength DESC LIMIT 10;
Expand Down
2 changes: 1 addition & 1 deletion src/mahoji/commands/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ GROUP BY type
ORDER BY qty DESC
LIMIT 15;`),
prisma.$queryRawUnsafe(`
SELECT sum(duration)
SELECT sum(duration)::int
FROM activity
WHERE user_id = ${id}
${whereInMassClause(id)};`)
Expand Down
2 changes: 1 addition & 1 deletion src/mahoji/lib/abstracted_commands/infernoCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function baseDuration(_attempts: number) {
async function timesMadeToZuk(userID: string) {
const timesMadeToZuk = Number(
(
await prisma.$queryRawUnsafe<any>(`SELECT COUNT(*)
await prisma.$queryRawUnsafe<any>(`SELECT COUNT(*)::int
FROM activity
WHERE type = 'Inferno'
AND user_id = ${userID}
Expand Down
Loading
Loading