[MM-15305] Migrate Preference.CleanupFlagsBatch to Sync by default (#10858)
* [MM-15305] Migrate Preference.CleanupFlagsBatch to Sync by default * clean up code in CleanupFlagsBatch
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
88005fbf54
Коммит
6158adb5b4
@@ -287,45 +287,42 @@ func (s SqlPreferenceStore) DeleteCategoryAndName(category string, name string)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlPreferenceStore) CleanupFlagsBatch(limit int64) store.StoreChannel {
|
func (s SqlPreferenceStore) CleanupFlagsBatch(limit int64) (int64, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
query :=
|
||||||
query :=
|
`DELETE FROM
|
||||||
`DELETE FROM
|
Preferences
|
||||||
Preferences
|
WHERE
|
||||||
WHERE
|
Category = :Category
|
||||||
Category = :Category
|
AND Name IN (
|
||||||
AND Name IN (
|
SELECT
|
||||||
|
*
|
||||||
|
FROM (
|
||||||
SELECT
|
SELECT
|
||||||
*
|
Preferences.Name
|
||||||
FROM (
|
FROM
|
||||||
SELECT
|
Preferences
|
||||||
Preferences.Name
|
LEFT JOIN
|
||||||
FROM
|
Posts
|
||||||
Preferences
|
ON
|
||||||
LEFT JOIN
|
Preferences.Name = Posts.Id
|
||||||
Posts
|
WHERE
|
||||||
ON
|
Preferences.Category = :Category
|
||||||
Preferences.Name = Posts.Id
|
AND Posts.Id IS null
|
||||||
WHERE
|
LIMIT
|
||||||
Preferences.Category = :Category
|
:Limit
|
||||||
AND Posts.Id IS null
|
)
|
||||||
LIMIT
|
AS t
|
||||||
:Limit
|
)`
|
||||||
)
|
|
||||||
AS t
|
|
||||||
)`
|
|
||||||
|
|
||||||
sqlResult, err := s.GetMaster().Exec(query, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_FLAGGED_POST, "Limit": limit})
|
sqlResult, err := s.GetMaster().Exec(query, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_FLAGGED_POST, "Limit": limit})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlPostStore.CleanupFlagsBatch", "store.sql_preference.cleanup_flags_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
return int64(0), 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 {
|
rowsAffected, err := sqlResult.RowsAffected()
|
||||||
result.Err = model.NewAppError("SqlPostStore.CleanupFlagsBatch", "store.sql_preference.cleanup_flags_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
if err != nil {
|
||||||
result.Data = int64(0)
|
return int64(0), model.NewAppError("SqlPostStore.CleanupFlagsBatch", "store.sql_preference.cleanup_flags_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
}
|
||||||
result.Data = rowsAffected
|
|
||||||
}
|
return rowsAffected, nil
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -437,7 +437,7 @@ type PreferenceStore interface {
|
|||||||
DeleteCategoryAndName(category string, name string) StoreChannel
|
DeleteCategoryAndName(category string, name string) StoreChannel
|
||||||
PermanentDeleteByUser(userId string) *model.AppError
|
PermanentDeleteByUser(userId string) *model.AppError
|
||||||
IsFeatureEnabled(feature, userId string) StoreChannel
|
IsFeatureEnabled(feature, userId string) StoreChannel
|
||||||
CleanupFlagsBatch(limit int64) StoreChannel
|
CleanupFlagsBatch(limit int64) (int64, *model.AppError)
|
||||||
}
|
}
|
||||||
|
|
||||||
type LicenseStore interface {
|
type LicenseStore interface {
|
||||||
|
|||||||
@@ -14,19 +14,26 @@ type PreferenceStore struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CleanupFlagsBatch provides a mock function with given fields: limit
|
// 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)
|
ret := _m.Called(limit)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 int64
|
||||||
if rf, ok := ret.Get(0).(func(int64) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(int64) int64); ok {
|
||||||
r0 = rf(limit)
|
r0 = rf(limit)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
r0 = ret.Get(0).(int64)
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
}
|
||||||
|
|
||||||
|
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
|
// 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}))
|
store.Must(ss.Preference().Save(&model.Preferences{preference1, preference2}))
|
||||||
|
|
||||||
result := <-ss.Preference().CleanupFlagsBatch(10000)
|
_, err := ss.Preference().CleanupFlagsBatch(10000)
|
||||||
assert.Nil(t, result.Err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
_, err := ss.Preference().Get(userId, category, preference1.Name)
|
_, err = ss.Preference().Get(userId, category, preference1.Name)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
_, err = ss.Preference().Get(userId, category, preference2.Name)
|
_, err = ss.Preference().Get(userId, category, preference2.Name)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user