Этот коммит содержится в:
Chris
2017-10-06 08:12:10 -07:00
коммит произвёл Joram Wilander
родитель 12501673d0
Коммит 363568b4eb
35 изменённых файлов: 589 добавлений и 3269 удалений

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

@@ -38,22 +38,14 @@ func (s SqlCommandWebhookStore) CreateIndexesIfNotExists() {
}
func (s SqlCommandWebhookStore) Save(webhook *model.CommandWebhook) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
if len(webhook.Id) > 0 {
result.Err = model.NewAppError("SqlCommandWebhookStore.Save", "store.sql_command_webhooks.save.existing.app_error", nil, "id="+webhook.Id, http.StatusBadRequest)
storeChannel <- result
close(storeChannel)
return
}
webhook.PreSave()
if result.Err = webhook.IsValid(); result.Err != nil {
storeChannel <- result
close(storeChannel)
return
}
@@ -62,20 +54,11 @@ func (s SqlCommandWebhookStore) Save(webhook *model.CommandWebhook) store.StoreC
} else {
result.Data = webhook
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (s SqlCommandWebhookStore) Get(id string) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
var webhook model.CommandWebhook
exptime := model.GetMillis() - model.COMMAND_WEBHOOK_LIFETIME
@@ -87,20 +70,11 @@ func (s SqlCommandWebhookStore) Get(id string) store.StoreChannel {
}
result.Data = &webhook
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (s SqlCommandWebhookStore) TryUse(id string, limit int) store.StoreChannel {
storeChannel := make(store.StoreChannel, 1)
go func() {
result := store.StoreResult{}
return store.Do(func(result *store.StoreResult) {
if sqlResult, err := s.GetMaster().Exec("UPDATE CommandWebhooks SET UseCount = UseCount + 1 WHERE Id = :Id AND UseCount < :UseLimit", map[string]interface{}{"Id": id, "UseLimit": limit}); err != nil {
result.Err = model.NewAppError("SqlCommandWebhookStore.TryUse", "store.sql_command_webhooks.try_use.app_error", nil, "id="+id+", err="+err.Error(), http.StatusInternalServerError)
} else if rows, _ := sqlResult.RowsAffected(); rows == 0 {
@@ -108,12 +82,7 @@ func (s SqlCommandWebhookStore) TryUse(id string, limit int) store.StoreChannel
}
result.Data = id
storeChannel <- result
close(storeChannel)
}()
return storeChannel
})
}
func (s SqlCommandWebhookStore) Cleanup() {