mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-15305] Migrate Preference.CleanupFlagsBatch to Sync by default (#10858)
* [MM-15305] Migrate Preference.CleanupFlagsBatch to Sync by default * clean up code in CleanupFlagsBatch
This commit is contained in:
@@ -287,45 +287,42 @@ func (s SqlPreferenceStore) DeleteCategoryAndName(category string, name string)
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlPreferenceStore) CleanupFlagsBatch(limit int64) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query :=
|
||||
`DELETE FROM
|
||||
Preferences
|
||||
WHERE
|
||||
Category = :Category
|
||||
AND Name IN (
|
||||
func (s SqlPreferenceStore) CleanupFlagsBatch(limit int64) (int64, *model.AppError) {
|
||||
query :=
|
||||
`DELETE FROM
|
||||
Preferences
|
||||
WHERE
|
||||
Category = :Category
|
||||
AND Name IN (
|
||||
SELECT
|
||||
*
|
||||
FROM (
|
||||
SELECT
|
||||
*
|
||||
FROM (
|
||||
SELECT
|
||||
Preferences.Name
|
||||
FROM
|
||||
Preferences
|
||||
LEFT JOIN
|
||||
Posts
|
||||
ON
|
||||
Preferences.Name = Posts.Id
|
||||
WHERE
|
||||
Preferences.Category = :Category
|
||||
AND Posts.Id IS null
|
||||
LIMIT
|
||||
:Limit
|
||||
)
|
||||
AS t
|
||||
)`
|
||||
Preferences.Name
|
||||
FROM
|
||||
Preferences
|
||||
LEFT JOIN
|
||||
Posts
|
||||
ON
|
||||
Preferences.Name = Posts.Id
|
||||
WHERE
|
||||
Preferences.Category = :Category
|
||||
AND Posts.Id IS null
|
||||
LIMIT
|
||||
:Limit
|
||||
)
|
||||
AS t
|
||||
)`
|
||||
|
||||
sqlResult, err := s.GetMaster().Exec(query, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_FLAGGED_POST, "Limit": limit})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.CleanupFlagsBatch", "store.sql_preference.cleanup_flags_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
rowsAffected, err1 := sqlResult.RowsAffected()
|
||||
if err1 != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.CleanupFlagsBatch", "store.sql_preference.cleanup_flags_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
||||
result.Data = int64(0)
|
||||
} else {
|
||||
result.Data = rowsAffected
|
||||
}
|
||||
}
|
||||
})
|
||||
sqlResult, err := s.GetMaster().Exec(query, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_FLAGGED_POST, "Limit": limit})
|
||||
if err != nil {
|
||||
return int64(0), model.NewAppError("SqlPostStore.CleanupFlagsBatch", "store.sql_preference.cleanup_flags_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
rowsAffected, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return int64(0), model.NewAppError("SqlPostStore.CleanupFlagsBatch", "store.sql_preference.cleanup_flags_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return rowsAffected, nil
|
||||
}
|
||||
|
||||
@@ -437,7 +437,7 @@ type PreferenceStore interface {
|
||||
DeleteCategoryAndName(category string, name string) StoreChannel
|
||||
PermanentDeleteByUser(userId string) *model.AppError
|
||||
IsFeatureEnabled(feature, userId string) StoreChannel
|
||||
CleanupFlagsBatch(limit int64) StoreChannel
|
||||
CleanupFlagsBatch(limit int64) (int64, *model.AppError)
|
||||
}
|
||||
|
||||
type LicenseStore interface {
|
||||
|
||||
@@ -14,19 +14,26 @@ type PreferenceStore struct {
|
||||
}
|
||||
|
||||
// CleanupFlagsBatch provides a mock function with given fields: limit
|
||||
func (_m *PreferenceStore) CleanupFlagsBatch(limit int64) store.StoreChannel {
|
||||
func (_m *PreferenceStore) CleanupFlagsBatch(limit int64) (int64, *model.AppError) {
|
||||
ret := _m.Called(limit)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(int64) store.StoreChannel); ok {
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(int64) int64); ok {
|
||||
r0 = rf(limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(int64) *model.AppError); ok {
|
||||
r1 = rf(limit)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Delete provides a mock function with given fields: userId, category, name
|
||||
|
||||
@@ -436,10 +436,10 @@ func testPreferenceCleanupFlagsBatch(t *testing.T, ss store.Store) {
|
||||
|
||||
store.Must(ss.Preference().Save(&model.Preferences{preference1, preference2}))
|
||||
|
||||
result := <-ss.Preference().CleanupFlagsBatch(10000)
|
||||
assert.Nil(t, result.Err)
|
||||
_, err := ss.Preference().CleanupFlagsBatch(10000)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, err := ss.Preference().Get(userId, category, preference1.Name)
|
||||
_, err = ss.Preference().Get(userId, category, preference1.Name)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, err = ss.Preference().Get(userId, category, preference2.Name)
|
||||
|
||||
Reference in New Issue
Block a user