fix caching

This commit is contained in:
2025-04-04 02:12:45 +02:00
parent 21b04afd10
commit 1e16b4c01d
7 changed files with 166 additions and 144 deletions

View File

@@ -32,7 +32,6 @@ export async function syncHistory() {
.where(eq(metadata.key, 'history_cursor'))
.limit(1)
.then((res) => res[0])
console.log('cursor', cursor)
const data = await ky
.get('https://api.neatqueue.com/api/history/1226193436521267223', {
searchParams: {
@@ -64,9 +63,6 @@ export async function syncHistory() {
value: firstGame,
},
})
console.log('matches', matches)
console.log('firstGame', firstGame)
console.log('data', data)
const chunkedData = chunk(data.data, 100)
for (const chunk of chunkedData) {

View File

@@ -1,9 +1,6 @@
import { createTRPCRouter, publicProcedure } from '@/server/api/trpc'
import { LeaderboardService } from '@/server/services/leaderboard'
import {
type LeaderboardResponse,
neatqueue_service,
} from '@/server/services/neatqueue.service'
import type { LeaderboardResponse } from '@/server/services/neatqueue.service'
import { z } from 'zod'
const service = new LeaderboardService()
@@ -17,7 +14,7 @@ export const leaderboard_router = createTRPCRouter({
.query(async ({ input }) => {
return (await service.getLeaderboard(
input.channel_id
)) as LeaderboardResponse
)) as LeaderboardResponse['alltime']
}),
get_user_rank: publicProcedure
.input(

View File

@@ -21,18 +21,12 @@ export class LeaderboardService {
const pipeline = redis.pipeline()
pipeline.del(zsetKey) // clear existing
for (const entry of fresh.alltime) {
for (const entry of fresh) {
// store by mmr for ranking
pipeline.zadd(zsetKey, entry.data.mmr, entry.id)
pipeline.zadd(zsetKey, entry.rank, entry.id)
// store user data separately for quick lookups
pipeline.hset(`user:${entry.id}`, {
name: entry.name,
mmr: entry.data.mmr,
wins: entry.data.wins,
losses: entry.data.losses,
// add other fields you need for quick lookup
})
pipeline.hset(`user:${entry.id}`, entry)
}
pipeline.expire(zsetKey, 180)

View File

@@ -11,11 +11,23 @@ const BMM_SERVER_ID = '1226193436521267223'
export const neatqueue_service = {
get_leaderboard: async (channel_id: string) => {
const response = await instance.get(
`leaderboard/${BMM_SERVER_ID}/${channel_id}`
)
const res = await instance
.get(`leaderboard/${BMM_SERVER_ID}/${channel_id}`)
.json<LeaderboardResponse>()
return response.json<LeaderboardResponse>()
//desc
res.alltime.sort((a, b) => b.data.mmr - a.data.mmr)
const fixed: Array<Data & { id: string; name: string }> = res.alltime.map(
(entry, idx) => {
return {
...entry.data,
rank: idx + 1,
id: entry.id,
name: entry.name,
}
}
)
return fixed
},
get_history: async (
player_ids: string[],