refactor: remove patch_detector and use gameVersion field in match_collector
This commit is contained in:
@@ -19,11 +19,38 @@ async function connectToDatabase() {
|
||||
return client
|
||||
}
|
||||
|
||||
async function fetchLatestPatch(client: MongoClient) {
|
||||
const database = client.db('patches')
|
||||
const patches = database.collection('patches')
|
||||
const latestPatch = await patches.find().limit(1).sort({ date: -1 }).next()
|
||||
return latestPatch!.patch as string
|
||||
/**
|
||||
* Get the latest patch from existing match collections in the database.
|
||||
* Collections are named like "15.1_EUW1", "15.2_NA1", etc.
|
||||
*/
|
||||
async function fetchLatestPatch(client: MongoClient): Promise<string> {
|
||||
const matchesDb = client.db('matches')
|
||||
const collections = await matchesDb.listCollections().toArray()
|
||||
const collectionNames = collections.map(c => c.name)
|
||||
|
||||
// Extract unique patch versions from collection names
|
||||
const patches = new Set<string>()
|
||||
for (const name of collectionNames) {
|
||||
// Collection names are either "patch_platform" or just "patch"
|
||||
const patch = name.split('_')[0]
|
||||
if (patch && /^\d+\.\d+$/.test(patch)) {
|
||||
patches.add(patch)
|
||||
}
|
||||
}
|
||||
|
||||
if (patches.size === 0) {
|
||||
throw new Error('No patch collections found in database')
|
||||
}
|
||||
|
||||
// Sort patches and return the latest (highest version number)
|
||||
const sortedPatches = Array.from(patches).sort((a, b) => {
|
||||
const [aMajor, aMinor] = a.split('.').map(Number)
|
||||
const [bMajor, bMinor] = b.split('.').map(Number)
|
||||
if (aMajor !== bMajor) return bMajor - aMajor
|
||||
return bMinor - aMinor
|
||||
})
|
||||
|
||||
return sortedPatches[0]
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user