Skip to content

Commit

Permalink
perf: using kysely
Browse files Browse the repository at this point in the history
  • Loading branch information
xandjiji committed Apr 12, 2024
1 parent 38f9742 commit c664c5c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
10 changes: 6 additions & 4 deletions apps/exevo-pan/src/pages/api/auction-bidded.ts
@@ -1,5 +1,5 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { prisma } from 'lib/prisma'
import { db } from 'db'
import { caller } from 'pages/api/trpc/[trpc]'
import { officialAuctionUrl } from 'utils'

Expand Down Expand Up @@ -29,9 +29,11 @@ export default async (
const auctionId = +request.query.auctionId

try {
const notifyList = await prisma.auctionNotification.findMany({
where: { auctionId },
})
const notifyList = await db
.selectFrom('AuctionNotification')
.where('auctionId', '=', auctionId)
.select(['userId', 'nickname'])
.execute()

await Promise.all(
notifyList.map(({ userId, nickname }) =>
Expand Down
35 changes: 21 additions & 14 deletions apps/exevo-pan/src/pages/api/auction-reminder.ts
@@ -1,5 +1,5 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { prisma } from 'lib/prisma'
import { db } from 'db'
import { caller } from 'pages/api/trpc/[trpc]'
import { MILLISECONDS_IN, officialAuctionUrl } from 'utils'

Expand All @@ -19,15 +19,17 @@ export default async (
}

try {
const notifyList = await prisma.auctionNotification.findMany({
where: {
notifyAt: {
lte: offsetCurrentDateByMinutes(2),
gte: offsetCurrentDateByMinutes(-10),
},
scheduleCompleted: false,
},
})
const notifyList = await db
.selectFrom('AuctionNotification')
.where((eb) =>
eb.and([
eb('scheduleCompleted', '=', false),
eb('notifyAt', '<=', offsetCurrentDateByMinutes(2)),
eb('notifyAt', '>=', offsetCurrentDateByMinutes(-10)),
]),
)
.select(['id', 'userId', 'nickname', 'auctionId'])
.execute()

await Promise.all(
notifyList.map(({ userId, nickname, auctionId }) =>
Expand All @@ -40,10 +42,15 @@ export default async (
),
)

await prisma.auctionNotification.updateMany({
where: { id: { in: notifyList.map(({ id }) => id) } },
data: { scheduleCompleted: true },
})
await db
.updateTable('AuctionNotification')
.where(
'id',
'in',
notifyList.map(({ id }) => id),
)
.set('scheduleCompleted', true)
.execute()

response.send('ok')
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions apps/exevo-pan/src/pages/api/cache-guild-stats.ts
@@ -1,7 +1,7 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-restricted-syntax */
import { NextApiRequest, NextApiResponse } from 'next'
import { prisma } from 'lib/prisma'
import { db } from 'db'
import { caller } from 'pages/api/trpc/[trpc]'

export default async (
Expand All @@ -21,7 +21,7 @@ export default async (

try {
const t0 = +new Date()
const guildIds = await prisma.guild.findMany({ select: { id: true } })
const guildIds = await db.selectFrom('Guild').select('id').execute()

uncachedIds = new Set(guildIds.map(({ id }) => id))

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -40,7 +40,7 @@
"checkup": "yarn --cwd apps/bazaar-scraper checkup",
"prisma:push": "yarn --cwd packages/db push",
"prisma:generate": "yarn --cwd packages/db generate",
"prisma:run": "scripts/setupDev.sh && yarn --cwd packages/db execute",
"prisma:run": "yarn --cwd packages/db execute",
"prisma:studio": "yarn --cwd packages/db studio"
},
"devDependencies": {
Expand Down

0 comments on commit c664c5c

Please sign in to comment.