MM-49564: Drafts upsert in the Store vs App layer (#22530)

* MM-49564: Upsert in the Store vs App layer

Refactor drafts so that Upserting a draft would happen in the DB and not
in the app layer.

* Fixes mocks

* Fixes tests

* Fixes translations

* Fixes tests

* Update tests

* Fixes tests

* Addresses review comments

- renames Save => Upsert
- removes Sleep from tests

* Fixes flaky test

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Kyriakos Z
2023-04-01 10:32:40 +03:00
коммит произвёл GitHub
родитель 4a3c853636
Коммит 4d2ed469bf
15 изменённых файлов: 113 добавлений и 395 удалений

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

@@ -3703,32 +3703,11 @@ func (s *RetryLayerDraftStore) GetDraftsForUser(userID string, teamID string) ([
}
func (s *RetryLayerDraftStore) Save(d *model.Draft) (*model.Draft, error) {
func (s *RetryLayerDraftStore) Upsert(d *model.Draft) (*model.Draft, error) {
tries := 0
for {
result, err := s.DraftStore.Save(d)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
timepkg.Sleep(100 * timepkg.Millisecond)
}
}
func (s *RetryLayerDraftStore) Update(d *model.Draft) (*model.Draft, error) {
tries := 0
for {
result, err := s.DraftStore.Update(d)
result, err := s.DraftStore.Upsert(d)
if err == nil {
return result, nil
}