Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
i2_bot/lib/datacache/exported.go
Vladimir Hodakov b8226d8aa8 DataCache and changes for game update
Recent game update changed pokememes view in pokedeks, so we need to
reflect it by updating parser.

Introducing DataCache - a silver bullet for eliminating lags linked to
database queries. Less queries, more in RAM, faster work. Needs testing
in production environment.
2018-01-29 23:50:25 +04:00

77 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2018 Vladimir "fat0troll" Hodakov
package datacache
import (
"git.wtfteam.pro/fat0troll/i2_bot/lib/appcontext"
"git.wtfteam.pro/fat0troll/i2_bot/lib/datacache/datacacheinterface"
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
"sync"
)
var (
c *appcontext.Context
)
// DataCache is a function-handling struct for package datacache.
// Also, it's a data cache: it handles all data, powered by DataCache functions.
type DataCache struct {
// Players — users of bot
players map[int]*dbmapping.Player
playersMutex sync.Mutex
// Profiles - game profiles, no matter, actual or not
profiles map[int]*dbmapping.Profile
profilesMutex sync.Mutex
// Current profiles - actual profiles for players, mostly used by bot
// Note: int in this array for player ID, not for profile ID
currentProfiles map[int]*dbmapping.Profile
currentProfilesMutex sync.Mutex
// Pokememes
pokememes map[int]*dbmapping.Pokememe
pokememesMutex sync.Mutex
// Pokememes with all supported data
fullPokememes map[int]*dbmapping.PokememeFull
fullPokememesMutex sync.Mutex
// Elements
elements map[int]*dbmapping.Element
elementsMutex sync.Mutex
// Leagues
leagues map[int]*dbmapping.League
leaguesMutex sync.Mutex
// Locations
locations map[int]*dbmapping.Location
locationsMutex sync.Mutex
// Weapons
weapons map[int]*dbmapping.Weapon
weaponsMutex sync.Mutex
}
// New is an initialization function for appcontext
func New(ac *appcontext.Context) {
c = ac
dc := &DataCache{}
c.RegisterDataCacheInterface(datacacheinterface.DataCacheInterface(dc))
}
// Init is a initialization function for package
func (dc *DataCache) Init() {
c.Log.Info("Initializing DataCache...")
dc.initElements()
dc.loadElements()
dc.initLeagues()
dc.loadLeagues()
dc.initLocations()
dc.loadLocations()
dc.initWeapons()
dc.loadWeapons()
dc.initPokememes()
dc.loadPokememes()
dc.initPlayers()
dc.loadPlayers()
dc.initProfiles()
dc.loadProfiles()
}