Skip to content

Commit

Permalink
Performance improvements (#612)
Browse files Browse the repository at this point in the history
* Monster tracking performance improvements

* Tidy

* Push DTS generation out of main loop

* Push DTS generation out of main loop

Co-authored-by: James Berry <[email protected]>
  • Loading branch information
jfberry and jfberry authored Nov 17, 2021
1 parent e7f4494 commit fc79fb6
Show file tree
Hide file tree
Showing 7 changed files with 870 additions and 758 deletions.
6 changes: 6 additions & 0 deletions src/controllerWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,5 +297,11 @@ if (!isMainThread) {
controllerWeatherManager.on('weatherForecastRequested', (data) => notifyWeatherController('weatherForecastRequested', data))

monsterController.on('userCares', (data) => notifyWeatherController('userCares', data))
monsterController.on('postMessage', (jobs) => queuePort.postMessage({ queue: jobs }))
raidController.on('postMessage', (jobs) => queuePort.postMessage({ queue: jobs }))
pokestopController.on('postMessage', (jobs) => queuePort.postMessage({ queue: jobs }))
pokestopLureController.on('postMessage', (jobs) => queuePort.postMessage({ queue: jobs }))
gymController.on('postMessage', (jobs) => queuePort.postMessage({ queue: jobs }))

setInterval(currentStatus, 60000)
}
135 changes: 71 additions & 64 deletions src/controllers/gym.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,72 +147,79 @@ class Gym extends Controller {
return []
}

data.imgUrl = await this.imgUicons.gymIcon(data.teamId, data.slotsAvailable, false, data.ex)
data.stickerUrl = await this.stickerUicons.gymIcon(data.teamId, data.slotsAvailable, false, data.ex)

const geoResult = await this.getAddress({ lat: data.latitude, lon: data.longitude })
const jobs = []

await this.getStaticMapUrl(logReference, data, 'gym', ['teamId', 'latitude', 'longitude', 'imgUrl'])
data.staticmap = data.staticMap // deprecated

for (const cares of whoCares) {
this.log.debug(`${logReference}: Creating gym alert for ${cares.id} ${cares.name} ${cares.type} ${cares.language} ${cares.template}`, cares)

const rateLimitTtr = this.getRateLimitTimeToRelease(cares.id)
if (rateLimitTtr) {
this.log.verbose(`${logReference}: Not creating gym alert (Rate limit) for ${cares.type} ${cares.id} ${cares.name} Time to release: ${rateLimitTtr}`)
// eslint-disable-next-line no-continue
continue
}
this.log.verbose(`${logReference}: Creating gym alert for ${cares.type} ${cares.id} ${cares.name} ${cares.language} ${cares.template}`)

const language = cares.language || this.config.general.locale
const translator = this.translatorFactory.Translator(language)
let [platform] = cares.type.split(':')
if (platform === 'webhook') platform = 'discord'

data.teamName = translator.translate(data.teamNameEng)
data.oldTeamName = translator.translate(data.oldTeamNameEng)
data.previousControlName = translator.translate(data.previousControlNameEng)
data.teamEmojiEng = data.teamId >= 0 ? this.emojiLookup.lookup(this.GameData.utilData.teams[data.teamId].emoji, platform) : ''
data.teamEmoji = translator.translate(data.teamEmojiEng)

// full build

const view = {
...geoResult,
...data,
time: data.distime,
tthh: data.tth.hours,
tthm: data.tth.minutes,
tths: data.tth.seconds,
now: new Date(),
nowISO: new Date().toISOString(),
areas: data.matchedAreas.filter((area) => area.displayInMatches).map((area) => area.name).join(', '),
setImmediate(async () => {
try {
data.imgUrl = await this.imgUicons.gymIcon(data.teamId, data.slotsAvailable, false, data.ex)
data.stickerUrl = await this.stickerUicons.gymIcon(data.teamId, data.slotsAvailable, false, data.ex)

const geoResult = await this.getAddress({ lat: data.latitude, lon: data.longitude })
const jobs = []

await this.getStaticMapUrl(logReference, data, 'gym', ['teamId', 'latitude', 'longitude', 'imgUrl'])
data.staticmap = data.staticMap // deprecated

for (const cares of whoCares) {
this.log.debug(`${logReference}: Creating gym alert for ${cares.id} ${cares.name} ${cares.type} ${cares.language} ${cares.template}`, cares)

const rateLimitTtr = this.getRateLimitTimeToRelease(cares.id)
if (rateLimitTtr) {
this.log.verbose(`${logReference}: Not creating gym alert (Rate limit) for ${cares.type} ${cares.id} ${cares.name} Time to release: ${rateLimitTtr}`)
// eslint-disable-next-line no-continue
continue
}
this.log.verbose(`${logReference}: Creating gym alert for ${cares.type} ${cares.id} ${cares.name} ${cares.language} ${cares.template}`)

const language = cares.language || this.config.general.locale
const translator = this.translatorFactory.Translator(language)
let [platform] = cares.type.split(':')
if (platform === 'webhook') platform = 'discord'

data.teamName = translator.translate(data.teamNameEng)
data.oldTeamName = translator.translate(data.oldTeamNameEng)
data.previousControlName = translator.translate(data.previousControlNameEng)
data.teamEmojiEng = data.teamId >= 0 ? this.emojiLookup.lookup(this.GameData.utilData.teams[data.teamId].emoji, platform) : ''
data.teamEmoji = translator.translate(data.teamEmojiEng)

// full build

const view = {
...geoResult,
...data,
time: data.distime,
tthh: data.tth.hours,
tthm: data.tth.minutes,
tths: data.tth.seconds,
now: new Date(),
nowISO: new Date().toISOString(),
areas: data.matchedAreas.filter((area) => area.displayInMatches).map((area) => area.name).join(', '),
}

const templateType = 'gym'
const message = await this.createMessage(logReference, templateType, platform, cares.template, language, cares.ping, view)

const work = {
lat: data.latitude.toString().substring(0, 8),
lon: data.longitude.toString().substring(0, 8),
message,
target: cares.id,
type: cares.type,
name: cares.name,
tth: data.tth,
clean: cares.clean,
emoji: data.emoji,
logReference,
language,
}

jobs.push(work)
}
this.emit('postMessage', jobs)
} catch (e) {
this.log.error(`${data.id || data.gym_id}: Can't seem to handle gym (user cares): `, e, data)
}
})

const templateType = 'gym'
const message = await this.createMessage(logReference, templateType, platform, cares.template, language, cares.ping, view)

const work = {
lat: data.latitude.toString().substring(0, 8),
lon: data.longitude.toString().substring(0, 8),
message,
target: cares.id,
type: cares.type,
name: cares.name,
tth: data.tth,
clean: cares.clean,
emoji: data.emoji,
logReference,
language,
}

jobs.push(work)
}

return jobs
return []
} catch (e) {
this.log.error(`${data.id || data.gym_id}: Can't seem to handle gym: `, e, data)
}
Expand Down
Loading

0 comments on commit fc79fb6

Please sign in to comment.