Archived
1

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.
This commit is contained in:
2018-01-29 23:50:25 +04:00
parent 074fc4a1e3
commit b8226d8aa8
36 changed files with 1294 additions and 700 deletions

View File

@@ -10,8 +10,9 @@ import (
// RouteCallback routes inline requests to bot
func (r *Router) RouteCallback(update *tgbotapi.Update) string {
playerRaw, ok := c.Users.GetOrCreatePlayer(update.CallbackQuery.From.ID)
if !ok {
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.CallbackQuery.From.ID)
if err != nil {
c.Log.Error(err.Error())
return "fail"
}
@@ -20,9 +21,9 @@ func (r *Router) RouteCallback(update *tgbotapi.Update) string {
switch {
case enableAlarmCallback.MatchString(update.CallbackQuery.Data):
return c.Reminder.CreateAlarmSetting(update, &playerRaw)
return c.Reminder.CreateAlarmSetting(update, playerRaw)
case disableAlarmCallback.MatchString(update.CallbackQuery.Data):
return c.Reminder.DestroyAlarmSetting(update, &playerRaw)
return c.Reminder.DestroyAlarmSetting(update, playerRaw)
}
return "ok"

View File

@@ -11,8 +11,9 @@ import (
// RouteInline routes inline requests to bot
func (r *Router) RouteInline(update *tgbotapi.Update) string {
playerRaw, ok := c.Users.GetOrCreatePlayer(update.InlineQuery.From.ID)
if !ok {
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.InlineQuery.From.ID)
if err != nil {
c.Log.Error(err.Error())
return "fail"
}
@@ -73,7 +74,7 @@ func (r *Router) RouteInline(update *tgbotapi.Update) string {
Results: results,
}
_, err := c.Bot.AnswerInlineQuery(inlineConf)
_, err = c.Bot.AnswerInlineQuery(inlineConf)
if err != nil {
c.Log.Error(err.Error())
}

View File

@@ -9,8 +9,9 @@ import (
// RouteRequest decides, what to do with user input
func (r *Router) RouteRequest(update *tgbotapi.Update) string {
playerRaw, ok := c.Users.GetOrCreatePlayer(update.Message.From.ID)
if !ok {
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.Message.From.ID)
if err != nil {
c.Log.Error(err.Error())
// Silently fail
return "fail"
}
@@ -20,13 +21,10 @@ func (r *Router) RouteRequest(update *tgbotapi.Update) string {
return "fail"
}
c.Log.Debug("Received message from chat ")
c.Log.Debugln(chatRaw.TelegramID)
if update.Message.Chat.IsGroup() || update.Message.Chat.IsSuperGroup() {
return r.routeGroupRequest(update, &playerRaw, &chatRaw)
return r.routeGroupRequest(update, playerRaw, &chatRaw)
} else if update.Message.Chat.IsPrivate() {
return r.routePrivateRequest(update, &playerRaw, &chatRaw)
return r.routePrivateRequest(update, playerRaw, &chatRaw)
}
return "ok"