made the emoji store getByName method sync (#11324)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
9ce1aa4455
Коммит
d300f4a6ad
@@ -53,7 +53,7 @@ func (a *App) CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartIma
|
|||||||
return nil, model.NewAppError("createEmoji", "api.emoji.create.other_user.app_error", nil, "", http.StatusForbidden)
|
return nil, model.NewAppError("createEmoji", "api.emoji.create.other_user.app_error", nil, "", http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-a.Srv.Store.Emoji().GetByName(emoji.Name); result.Err == nil && result.Data != nil {
|
if existingEmoji, err := a.Srv.Store.Emoji().GetByName(emoji.Name); err == nil && existingEmoji != nil {
|
||||||
return nil, model.NewAppError("createEmoji", "api.emoji.create.duplicate.app_error", nil, "", http.StatusBadRequest)
|
return nil, model.NewAppError("createEmoji", "api.emoji.create.duplicate.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,11 +190,7 @@ func (a *App) GetEmojiByName(emojiName string) (*model.Emoji, *model.AppError) {
|
|||||||
return nil, model.NewAppError("GetEmoji", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
|
return nil, model.NewAppError("GetEmoji", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := <-a.Srv.Store.Emoji().GetByName(emojiName)
|
return a.Srv.Store.Emoji().GetByName(emojiName)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.(*model.Emoji), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetMultipleEmojiByName(names []string) ([]*model.Emoji, *model.AppError) {
|
func (a *App) GetMultipleEmojiByName(names []string) ([]*model.Emoji, *model.AppError) {
|
||||||
|
|||||||
@@ -1280,13 +1280,9 @@ func (a *App) ImportEmoji(data *EmojiImportData, dryRun bool) *model.AppError {
|
|||||||
|
|
||||||
var emoji *model.Emoji
|
var emoji *model.Emoji
|
||||||
|
|
||||||
result := <-a.Srv.Store.Emoji().GetByName(*data.Name)
|
emoji, appError := a.Srv.Store.Emoji().GetByName(*data.Name)
|
||||||
if result.Err != nil && result.Err.StatusCode != http.StatusNotFound {
|
if appError != nil && appError.StatusCode != http.StatusNotFound {
|
||||||
return result.Err
|
return appError
|
||||||
}
|
|
||||||
|
|
||||||
if result.Data != nil {
|
|
||||||
emoji = result.Data.(*model.Emoji)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
alreadyExists := emoji != nil
|
alreadyExists := emoji != nil
|
||||||
|
|||||||
@@ -2681,8 +2681,9 @@ func TestImportImportEmoji(t *testing.T) {
|
|||||||
err := th.App.ImportEmoji(&data, true)
|
err := th.App.ImportEmoji(&data, true)
|
||||||
assert.NotNil(t, err, "Invalid emoji should have failed dry run")
|
assert.NotNil(t, err, "Invalid emoji should have failed dry run")
|
||||||
|
|
||||||
result := <-th.App.Srv.Store.Emoji().GetByName(*data.Name)
|
emoji, err := th.App.Srv.Store.Emoji().GetByName(*data.Name)
|
||||||
assert.Nil(t, result.Data, "Emoji should not have been imported")
|
assert.Nil(t, emoji, "Emoji should not have been imported")
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
data.Image = ptrStr(testImage)
|
data.Image = ptrStr(testImage)
|
||||||
err = th.App.ImportEmoji(&data, true)
|
err = th.App.ImportEmoji(&data, true)
|
||||||
@@ -2700,8 +2701,9 @@ func TestImportImportEmoji(t *testing.T) {
|
|||||||
err = th.App.ImportEmoji(&data, false)
|
err = th.App.ImportEmoji(&data, false)
|
||||||
assert.Nil(t, err, "Valid emoji should have succeeded apply mode")
|
assert.Nil(t, err, "Valid emoji should have succeeded apply mode")
|
||||||
|
|
||||||
result = <-th.App.Srv.Store.Emoji().GetByName(*data.Name)
|
emoji, err = th.App.Srv.Store.Emoji().GetByName(*data.Name)
|
||||||
assert.NotNil(t, result.Data, "Emoji should have been imported")
|
assert.NotNil(t, emoji, "Emoji should have been imported")
|
||||||
|
assert.Nil(t, err, "Emoji should have been imported without any error")
|
||||||
|
|
||||||
err = th.App.ImportEmoji(&data, false)
|
err = th.App.ImportEmoji(&data, false)
|
||||||
assert.Nil(t, err, "Second run should have succeeded apply mode")
|
assert.Nil(t, err, "Second run should have succeeded apply mode")
|
||||||
|
|||||||
@@ -100,26 +100,27 @@ func (es SqlEmojiStore) Get(id string, allowFromCache bool) (*model.Emoji, *mode
|
|||||||
return emoji, nil
|
return emoji, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (es SqlEmojiStore) GetByName(name string) store.StoreChannel {
|
func (es SqlEmojiStore) GetByName(name string) (*model.Emoji, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
|
||||||
var emoji *model.Emoji
|
|
||||||
|
|
||||||
if err := es.GetReplica().SelectOne(&emoji,
|
var emoji *model.Emoji
|
||||||
`SELECT
|
|
||||||
*
|
if err := es.GetReplica().SelectOne(&emoji,
|
||||||
FROM
|
`SELECT
|
||||||
Emoji
|
*
|
||||||
WHERE
|
FROM
|
||||||
Name = :Name
|
Emoji
|
||||||
AND DeleteAt = 0`, map[string]interface{}{"Name": name}); err != nil {
|
WHERE
|
||||||
result.Err = model.NewAppError("SqlEmojiStore.GetByName", "store.sql_emoji.get_by_name.app_error", nil, "name="+name+", "+err.Error(), http.StatusInternalServerError)
|
Name = :Name
|
||||||
if err == sql.ErrNoRows {
|
AND DeleteAt = 0`, map[string]interface{}{"Name": name}); err != nil {
|
||||||
result.Err.StatusCode = http.StatusNotFound
|
|
||||||
}
|
if err == sql.ErrNoRows {
|
||||||
} else {
|
return nil, model.NewAppError("SqlEmojiStore.GetByName", "store.sql_emoji.get_by_name.app_error", nil, "name="+name+", "+err.Error(), http.StatusNotFound)
|
||||||
result.Data = emoji
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
return nil, model.NewAppError("SqlEmojiStore.GetByName", "store.sql_emoji.get_by_name.app_error", nil, "name="+name+", "+err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
return emoji, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (es SqlEmojiStore) GetMultipleByName(names []string) store.StoreChannel {
|
func (es SqlEmojiStore) GetMultipleByName(names []string) store.StoreChannel {
|
||||||
|
|||||||
@@ -456,7 +456,7 @@ type TokenStore interface {
|
|||||||
type EmojiStore interface {
|
type EmojiStore interface {
|
||||||
Save(emoji *model.Emoji) (*model.Emoji, *model.AppError)
|
Save(emoji *model.Emoji) (*model.Emoji, *model.AppError)
|
||||||
Get(id string, allowFromCache bool) (*model.Emoji, *model.AppError)
|
Get(id string, allowFromCache bool) (*model.Emoji, *model.AppError)
|
||||||
GetByName(name string) StoreChannel
|
GetByName(name string) (*model.Emoji, *model.AppError)
|
||||||
GetMultipleByName(names []string) StoreChannel
|
GetMultipleByName(names []string) StoreChannel
|
||||||
GetList(offset, limit int, sort string) StoreChannel
|
GetList(offset, limit int, sort string) StoreChannel
|
||||||
Delete(id string, time int64) *model.AppError
|
Delete(id string, time int64) *model.AppError
|
||||||
|
|||||||
@@ -134,8 +134,8 @@ func testEmojiGetByName(t *testing.T, ss store.Store) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
for _, emoji := range emojis {
|
for _, emoji := range emojis {
|
||||||
if result := <-ss.Emoji().GetByName(emoji.Name); result.Err != nil {
|
if _, err := ss.Emoji().GetByName(emoji.Name); err != nil {
|
||||||
t.Fatalf("failed to get emoji with name %v: %v", emoji.Name, result.Err)
|
t.Fatalf("failed to get emoji with name %v: %v", emoji.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,19 +55,28 @@ func (_m *EmojiStore) Get(id string, allowFromCache bool) (*model.Emoji, *model.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetByName provides a mock function with given fields: name
|
// GetByName provides a mock function with given fields: name
|
||||||
func (_m *EmojiStore) GetByName(name string) store.StoreChannel {
|
func (_m *EmojiStore) GetByName(name string) (*model.Emoji, *model.AppError) {
|
||||||
ret := _m.Called(name)
|
ret := _m.Called(name)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.Emoji
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) *model.Emoji); ok {
|
||||||
r0 = rf(name)
|
r0 = rf(name)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.Emoji)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||||
|
r1 = rf(name)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetList provides a mock function with given fields: offset, limit, sort
|
// GetList provides a mock function with given fields: offset, limit, sort
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user