* Add webhook cache

* Add channel by name cache

* Fxing profiles in channels cache

* Fix merge
Этот коммит содержится в:
Joram Wilander
2017-01-27 14:07:34 -05:00
коммит произвёл GitHub
родитель 8eab04e944
Коммит 097289f8e4
19 изменённых файлов: 173 добавлений и 51 удалений

Просмотреть файл

@@ -4,13 +4,26 @@
package store
import (
"github.com/mattermost/platform/einterfaces"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
)
type SqlWebhookStore struct {
*SqlStore
}
const (
WEBHOOK_CACHE_SIZE = 25000
WEBHOOK_CACHE_SEC = 900 // 15 minutes
)
var webhookCache = utils.NewLru(WEBHOOK_CACHE_SIZE)
func ClearWebhookCaches() {
webhookCache.Purge()
}
func NewSqlWebhookStore(sqlStore *SqlStore) WebhookStore {
s := &SqlWebhookStore{sqlStore}
@@ -54,6 +67,10 @@ func (s SqlWebhookStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_outgoing_webhook_delete_at", "OutgoingWebhooks", "DeleteAt")
}
func (s SqlWebhookStore) InvalidateWebhookCache(webhookId string) {
webhookCache.Remove(webhookId)
}
func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) StoreChannel {
storeChannel := make(StoreChannel, 1)
@@ -88,18 +105,39 @@ func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) StoreChann
return storeChannel
}
func (s SqlWebhookStore) GetIncoming(id string) StoreChannel {
func (s SqlWebhookStore) GetIncoming(id string, allowFromCache bool) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
if allowFromCache {
metrics := einterfaces.GetMetricsInterface()
if cacheItem, ok := webhookCache.Get(id); ok {
if metrics != nil {
metrics.IncrementMemCacheHitCounter("Webhook")
}
result.Data = cacheItem.(*model.IncomingWebhook)
storeChannel <- result
close(storeChannel)
return
} else {
if metrics != nil {
metrics.IncrementMemCacheMissCounter("Webhook")
}
}
}
var webhook model.IncomingWebhook
if err := s.GetReplica().SelectOne(&webhook, "SELECT * FROM IncomingWebhooks WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": id}); err != nil {
result.Err = model.NewLocAppError("SqlWebhookStore.GetIncoming", "store.sql_webhooks.get_incoming.app_error", nil, "id="+id+", err="+err.Error())
}
if result.Err == nil {
webhookCache.AddWithExpiresInSecs(id, &webhook, WEBHOOK_CACHE_SEC)
}
result.Data = &webhook
storeChannel <- result