From 8f437255f0f3e2b93b83e3dd2604b636b017059b Mon Sep 17 00:00:00 2001 From: TurtIeSocks <58572875+TurtIeSocks@users.noreply.github.com> Date: Sat, 18 Jun 2022 22:42:16 -0400 Subject: [PATCH] Available Slots Compatibility - Updates SQL query to use a dynamic column name based on a startup check - Maintains backwards compatibility for older RDM clients that are still using availble_slots --- .vscode/extensions.json | 3 +-- server/src/models/Gym.js | 10 +++++----- server/src/services/DbCheck.js | 12 ++++++++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index b274d30a3..d75a05ba5 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -5,7 +5,6 @@ "lokalise.i18n-ally", "esbenp.prettier-vscode", "leizongmin.node-module-intellisense", - "eg2.vscode-npm-script", - "2gua.rainbow-brackets" + "eg2.vscode-npm-script" ] } \ No newline at end of file diff --git a/server/src/models/Gym.js b/server/src/models/Gym.js index 888c8666e..b31b9dc07 100644 --- a/server/src/models/Gym.js +++ b/server/src/models/Gym.js @@ -21,7 +21,7 @@ module.exports = class Gym extends Model { return 'gym' } - static async getAll(perms, args, { isMad }, userId) { + static async getAll(perms, args, { isMad, availableSlotsCol }, userId) { const { gyms: gymPerms, raids: raidPerms, areaRestrictions, gymBadges } = perms const { onlyAllGyms, onlyRaids, onlyExEligible, onlyInBattle, onlyArEligible, onlyRaidTier, onlyGymBadges, onlyBadge, ts, @@ -167,7 +167,7 @@ module.exports = class Gym extends Model { if (teamSlots.length) { gym.orWhere(gymSlot => { gymSlot.where('team_id', team) - .whereIn(isMad ? 'slots_available' : 'availble_slots', teamSlots) + .whereIn(isMad ? 'slots_available' : availableSlotsCol, teamSlots) }) } }) @@ -252,7 +252,7 @@ module.exports = class Gym extends Model { return secondaryFilter(await query.limit(queryLimits.gyms)) } - static async getAvailable({ isMad }) { + static async getAvailable({ isMad, availableSlotsCol }) { const ts = Math.floor((new Date()).getTime() / 1000) const results = await this.query() .select([ @@ -272,11 +272,11 @@ module.exports = class Gym extends Model { const teamResults = await this.query() .select([ 'team_id AS team', - isMad ? 'slots_available AS slots' : 'availble_slots AS slots', + isMad ? 'slots_available AS slots' : `${availableSlotsCol} AS slots`, ]) .groupBy([ 'team_id', - isMad ? 'slots_available' : 'availble_slots', + isMad ? 'slots_available' : availableSlotsCol, ]) .then((r) => { const unique = new Set() diff --git a/server/src/services/DbCheck.js b/server/src/services/DbCheck.js index 5b1f3b745..6a774b173 100644 --- a/server/src/services/DbCheck.js +++ b/server/src/services/DbCheck.js @@ -49,8 +49,11 @@ module.exports = class DbCheck { console.log(`[DB] Determining database types for ${this.connections.length} connection${this.connections.length > 1 ? 's' : ''}`) await Promise.all(this.connections.map(async (schema, i) => { try { - const isMad = await schema('trs_quest').columnInfo().then(col => Object.keys(col).length > 0) - const pvpV2 = await schema('pokemon').columnInfo().then(col => 'pvp' in col) + const [isMad, pvpV2] = await schema('pokemon').columnInfo() + .then(columns => [ + 'cp_multiplier' in columns, + 'pvp' in columns, + ]) const [hasRewardAmount, hasAltQuests] = await schema('pokestop').columnInfo() .then(columns => ([ ('quest_reward_amount' in columns || isMad), @@ -61,6 +64,10 @@ module.exports = class DbCheck { 'character' in columns, 'expiration_ms' in columns, ])) + const [availableSlotsCol] = await schema('gym').columnInfo() + .then(columns => ([ + 'availble_slots' in columns ? 'availble_slots' : 'available_slots', + ])) Object.entries(this.models).forEach(([category, sources]) => { sources.forEach((source, j) => { if (source.connection === i) { @@ -70,6 +77,7 @@ module.exports = class DbCheck { this.models[category][j].hasAltQuests = hasAltQuests this.models[category][j].hasMultiInvasions = hasMultiInvasions this.models[category][j].multiInvasionMs = multiInvasionMs + this.models[category][j].availableSlotsCol = availableSlotsCol } }) })