MM-47171 Export direct channel favorites (#21570)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
279754c6b0
Коммит
b73bf144aa
@@ -6624,6 +6624,24 @@ func (s *OpenTracingLayerPreferenceStore) GetCategory(userID string, category st
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerPreferenceStore) GetCategoryAndName(category string, nane string) (model.Preferences, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.GetCategoryAndName")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.PreferenceStore.GetCategoryAndName(category, nane)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerPreferenceStore) PermanentDeleteByUser(userID string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PreferenceStore.PermanentDeleteByUser")
|
||||
|
||||
@@ -7515,6 +7515,27 @@ func (s *RetryLayerPreferenceStore) GetCategory(userID string, category string)
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerPreferenceStore) GetCategoryAndName(category string, nane string) (model.Preferences, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.PreferenceStore.GetCategoryAndName(category, nane)
|
||||
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 *RetryLayerPreferenceStore) PermanentDeleteByUser(userID string) error {
|
||||
|
||||
tries := 0
|
||||
|
||||
@@ -140,6 +140,23 @@ func (s SqlPreferenceStore) Get(userId string, category string, name string) (*m
|
||||
return &preference, nil
|
||||
}
|
||||
|
||||
func (s SqlPreferenceStore) GetCategoryAndName(category string, name string) (model.Preferences, error) {
|
||||
var preferences model.Preferences
|
||||
query, args, err := s.getQueryBuilder().
|
||||
Select("*").
|
||||
From("Preferences").
|
||||
Where(sq.Eq{"Category": category}).
|
||||
Where(sq.Eq{"Name": name}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not build sql query to get preference")
|
||||
}
|
||||
if err = s.GetReplicaX().Select(&preferences, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Preference with category=%s, name=%s", category, name)
|
||||
}
|
||||
return preferences, nil
|
||||
}
|
||||
|
||||
func (s SqlPreferenceStore) GetCategory(userId string, category string) (model.Preferences, error) {
|
||||
var preferences model.Preferences
|
||||
query, args, err := s.getQueryBuilder().
|
||||
|
||||
@@ -633,6 +633,7 @@ type CommandWebhookStore interface {
|
||||
type PreferenceStore interface {
|
||||
Save(preferences model.Preferences) error
|
||||
GetCategory(userID string, category string) (model.Preferences, error)
|
||||
GetCategoryAndName(category string, nane string) (model.Preferences, error)
|
||||
Get(userID string, category string, name string) (*model.Preference, error)
|
||||
GetAll(userID string) (model.Preferences, error)
|
||||
Delete(userID, category, name string) error
|
||||
|
||||
@@ -167,6 +167,29 @@ func (_m *PreferenceStore) GetCategory(userID string, category string) (model.Pr
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetCategoryAndName provides a mock function with given fields: category, nane
|
||||
func (_m *PreferenceStore) GetCategoryAndName(category string, nane string) (model.Preferences, error) {
|
||||
ret := _m.Called(category, nane)
|
||||
|
||||
var r0 model.Preferences
|
||||
if rf, ok := ret.Get(0).(func(string, string) model.Preferences); ok {
|
||||
r0 = rf(category, nane)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(model.Preferences)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, string) error); ok {
|
||||
r1 = rf(category, nane)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PermanentDeleteByUser provides a mock function with given fields: userID
|
||||
func (_m *PreferenceStore) PermanentDeleteByUser(userID string) error {
|
||||
ret := _m.Called(userID)
|
||||
|
||||
@@ -5987,6 +5987,22 @@ func (s *TimerLayerPreferenceStore) GetCategory(userID string, category string)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerPreferenceStore) GetCategoryAndName(category string, nane string) (model.Preferences, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.PreferenceStore.GetCategoryAndName(category, nane)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("PreferenceStore.GetCategoryAndName", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerPreferenceStore) PermanentDeleteByUser(userID string) error {
|
||||
start := time.Now()
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user