mirror of
https://github.com/ddworken/hishtory.git
synced 2025-04-01 03:47:52 +02:00
Optimize SQL query so it only runs one query rather than N
This commit is contained in:
parent
19bbf27efd
commit
80822c722e
@ -277,17 +277,15 @@ func addDeletionRequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func applyDeletionRequestsToBackend(request shared.DeletionRequest) (int, error) {
|
||||
numDeleted := 0
|
||||
tx := GLOBAL_DB.Where("false")
|
||||
for _, message := range request.Messages.Ids {
|
||||
// TODO: Optimize this into one query
|
||||
tx := GLOBAL_DB.Where("user_id = ? AND device_id = ? AND date = ?", request.UserId, message.DeviceId, message.Date)
|
||||
result := tx.Delete(&shared.EncHistoryEntry{})
|
||||
if result.Error != nil {
|
||||
return 0, result.Error
|
||||
}
|
||||
numDeleted += int(result.RowsAffected)
|
||||
tx = tx.Or(GLOBAL_DB.Where("user_id = ? AND device_id = ? AND date = ?", request.UserId, message.DeviceId, message.Date))
|
||||
}
|
||||
return numDeleted, nil
|
||||
result := tx.Delete(&shared.EncHistoryEntry{})
|
||||
if result.Error != nil {
|
||||
return 0, result.Error
|
||||
}
|
||||
return int(result.RowsAffected), nil
|
||||
}
|
||||
|
||||
func wipeDbHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
Loading…
Reference in New Issue
Block a user