Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-15305] Migrate Preference.CleanupFlagsBatch to Sync by default #10858

Merged
merged 4 commits into from May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
77 changes: 37 additions & 40 deletions store/sqlstore/preference_store.go
Expand Up @@ -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
)`

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
}
}
})
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 {
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
}
2 changes: 1 addition & 1 deletion store/store.go
Expand Up @@ -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 {
Expand Down
19 changes: 13 additions & 6 deletions store/storetest/mocks/PreferenceStore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions store/storetest/preference_store.go
Expand Up @@ -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)
Expand Down