mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 20:07:52 +02:00
Add ReadCount field to deletion requests so that we can eventually delete them from the DB
This commit is contained in:
parent
5391ecd220
commit
41f82e8034
@ -109,12 +109,15 @@ func apiQueryHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
deviceId := getRequiredQueryParam(r, "device_id")
|
deviceId := getRequiredQueryParam(r, "device_id")
|
||||||
updateUsageData(userId, deviceId)
|
updateUsageData(userId, deviceId)
|
||||||
// Increment the count
|
// Increment the count
|
||||||
GLOBAL_DB.Exec("UPDATE enc_history_entries SET read_count = read_count + 1 WHERE device_id = ?", deviceId)
|
result := GLOBAL_DB.Exec("UPDATE enc_history_entries SET read_count = read_count + 1 WHERE device_id = ?", deviceId)
|
||||||
|
if result.Error != nil {
|
||||||
|
panic(result.Error)
|
||||||
|
}
|
||||||
|
|
||||||
// Then retrieve, to avoid a race condition
|
// Then retrieve, to avoid a race condition
|
||||||
tx := GLOBAL_DB.Where("device_id = ? AND read_count < 5", deviceId)
|
tx := GLOBAL_DB.Where("device_id = ? AND read_count < 5", deviceId)
|
||||||
var historyEntries []*shared.EncHistoryEntry
|
var historyEntries []*shared.EncHistoryEntry
|
||||||
result := tx.Find(&historyEntries)
|
result = tx.Find(&historyEntries)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
panic(fmt.Errorf("DB query error: %v", result.Error))
|
panic(fmt.Errorf("DB query error: %v", result.Error))
|
||||||
}
|
}
|
||||||
@ -205,11 +208,18 @@ func apiBannerHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getDeletionRequestsHandler(w http.ResponseWriter, r *http.Request) {
|
func getDeletionRequestsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// TODO: Count how many times they've been read and eventually delete them
|
|
||||||
userId := getRequiredQueryParam(r, "user_id")
|
userId := getRequiredQueryParam(r, "user_id")
|
||||||
deviceId := getRequiredQueryParam(r, "device_id")
|
deviceId := getRequiredQueryParam(r, "device_id")
|
||||||
|
|
||||||
|
// Increment the ReadCount
|
||||||
|
result := GLOBAL_DB.Exec("UPDATE deletion_requesy SET read_count = read_count + 1 WHERE destination_device_id = ? AND user_id = ?", deviceId, userId)
|
||||||
|
if result.Error != nil {
|
||||||
|
panic(result.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return all the deletion requests
|
||||||
var deletionRequests []*shared.DeletionRequest
|
var deletionRequests []*shared.DeletionRequest
|
||||||
result := GLOBAL_DB.Where("user_id = ? AND destination_device_id = ?", userId, deviceId).Find(&deletionRequests)
|
result = GLOBAL_DB.Where("user_id = ? AND destination_device_id = ?", userId, deviceId).Find(&deletionRequests)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
panic(fmt.Errorf("DB query error: %v", result.Error))
|
panic(fmt.Errorf("DB query error: %v", result.Error))
|
||||||
}
|
}
|
||||||
@ -519,6 +529,10 @@ func cleanDatabase() error {
|
|||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return result.Error
|
return result.Error
|
||||||
}
|
}
|
||||||
|
result = GLOBAL_DB.Exec("DELETE FROM deletion_requests WHERE read_count > 100")
|
||||||
|
if result.Error != nil {
|
||||||
|
return result.Error
|
||||||
|
}
|
||||||
// TODO: Clean the database by deleting entries for users that haven't been used in X amount of time
|
// TODO: Clean the database by deleting entries for users that haven't been used in X amount of time
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,11 @@ type UpdateInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DeletionRequest struct {
|
type DeletionRequest struct {
|
||||||
// TODO: Add a ReadCount
|
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
DestinationDeviceId string `json:"destination_device_id"`
|
DestinationDeviceId string `json:"destination_device_id"`
|
||||||
SendTime time.Time `json:"send_time"`
|
SendTime time.Time `json:"send_time"`
|
||||||
Messages MessageIdentifiers `json:"messages"`
|
Messages MessageIdentifiers `json:"messages"`
|
||||||
|
ReadCount int `json:"read_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageIdentifiers struct {
|
type MessageIdentifiers struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user