Skip to content
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
10 changes: 5 additions & 5 deletions server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
"weather": 30
},
"queryUpdateHours": {
"pokemon": 0.5,
"quests": 1,
"raids": 0.5,
"nests": 3
"pokemon": 0.25,
"quests": 0.5,
"raids": 0.2,
"nests": 1
},
"queryOnSessionInit": {
"pokemon": false,
"quests": false,
"raids": false,
"raids": true,
"nests": false
},
"queryLimits": {
Expand Down
30 changes: 16 additions & 14 deletions server/src/routes/rootRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,31 +223,33 @@ rootRouter.get('/settings', async (req, res) => {
})

if (serverSettings.user.perms.pokemon) {
serverSettings.available.pokemon = config.api.queryOnSessionInit.pokemon
? await Db.getAvailable('Pokemon')
: Event.available.pokemon
if (config.api.queryOnSessionInit.pokemon) {
Event.setAvailable('pokemon', 'Pokemon', Db, false)
}
serverSettings.available.pokemon = Event.getAvailable('pokemon')
}
if (serverSettings.user.perms.raids || serverSettings.user.perms.gyms) {
serverSettings.available.gyms = config.api.queryOnSessionInit.raids
? await Db.getAvailable('Gym')
: Event.available.gyms
if (config.api.queryOnSessionInit.raids) {
Event.setAvailable('gyms', 'Gym', Db, false)
}
serverSettings.available.gyms = Event.getAvailable('gyms')
}
if (
serverSettings.user.perms.quests ||
serverSettings.user.perms.pokestops ||
serverSettings.user.perms.invasions ||
serverSettings.user.perms.lures
) {
serverSettings.available.pokestops = config.api.queryOnSessionInit
.quests
? await Db.getAvailable('Pokestop')
: Event.available.pokestops
serverSettings.available.withConditions = Db.questConditions
if (config.api.queryOnSessionInit.quests) {
Event.setAvailable('pokestops', 'Pokestop', Db, false)
}
serverSettings.available.pokestops = Event.getAvailable('pokestops')
}
if (serverSettings.user.perms.nests) {
serverSettings.available.nests = config.api.queryOnSessionInit.nests
? await Db.getAvailable('Nest')
: Event.available.nests
if (config.api.queryOnSessionInit.nests) {
Event.setAvailable('nests', 'Nest', Db, false)
}
serverSettings.available.nests = Event.getAvailable('nests')
}
if (Object.values(config.api.queryOnSessionInit).some((v) => v)) {
Event.addAvailable()
Expand Down
6 changes: 3 additions & 3 deletions server/src/services/DbCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ module.exports = class DbCheck {
return [DbCheck.deDupeResults(stopData), DbCheck.deDupeResults(gymData)]
}

async getAvailable(model) {
async getAvailable(model, log = true) {
if (this.models[model]) {
console.log(`[DB] Querying available for ${model}`)
if (log) console.log(`[DB] Querying available for ${model}`)
try {
const results = await Promise.all(
this.models[model].map(async (source) =>
source.SubModel.getAvailable(source),
),
)
console.log(`[DB] Setting available for ${model}`)
if (log) console.log(`[DB] Setting available for ${model}`)
if (model === 'Pokestop') {
results.forEach((result) => {
if ('conditions' in result) {
Expand Down
16 changes: 10 additions & 6 deletions server/src/services/EventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,33 @@ module.exports = class EventManager {
this.webhookObj = {}
}

async setAvailable(category, model, Db) {
this.available[category] = await Db.getAvailable(model)
getAvailable(category) {
return this.available[category]
}

async setAvailable(category, model, Db, log) {
this.available[category] = await Db.getAvailable(model, log)
}

setTimers(config, Db, Pvp) {
if (!config.api.queryOnSessionInit.raids) {
setInterval(async () => {
this.available.gyms = await Db.getAvailable('Gym')
await this.setAvailable('gyms', 'Gym', Db, true)
}, 1000 * 60 * 60 * (config.api.queryUpdateHours.raids || 1))
}
if (!config.api.queryOnSessionInit.nests) {
setInterval(async () => {
this.available.nests = await Db.getAvailable('Nest')
await this.setAvailable('nests', 'Nest', Db, true)
}, 1000 * 60 * 60 * (config.api.queryUpdateHours.nests || 6))
}
if (!config.api.queryOnSessionInit.pokemon) {
setInterval(async () => {
this.available.pokemon = await Db.getAvailable('Pokemon')
await this.setAvailable('pokemon', 'Pokemon', Db, true)
}, 1000 * 60 * 60 * (config.api.queryUpdateHours.pokemon || 1))
}
if (!config.api.queryOnSessionInit.quests) {
setInterval(async () => {
this.available.pokestops = await Db.getAvailable('Pokestop')
await this.setAvailable('pokestops', 'Pokestop', Db, true)
}, 1000 * 60 * 60 * (config.api.queryUpdateHours.quests || 3))
}
setInterval(async () => {
Expand Down
6 changes: 5 additions & 1 deletion server/src/services/functions/getAreaSql.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ module.exports = function getAreaRestrictionSql(
isMad,
category,
) {
if (!areaRestrictions?.length && (!onlyAreas?.length || config.manualAreas.length)) return true
if (
!areaRestrictions?.length &&
(!onlyAreas?.length || config.manualAreas.length)
)
return true

const cleanUserAreas = onlyAreas.filter((area) => areas.names.includes(area))
const consolidatedAreas = areaRestrictions.length
Expand Down