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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user