mirror of
https://github.com/ddworken/hishtory.git
synced 2024-10-05 01:42:03 +02:00
Remove duplicate entries before sending back to the user to save bandwidth for the client
This commit is contained in:
parent
3875bddddc
commit
05c71b2f21
@ -27,7 +27,19 @@ func (db *DB) AllHistoryEntriesForUser(ctx context.Context, userID string) ([]*s
|
|||||||
return nil, fmt.Errorf("tx.Error: %w", tx.Error)
|
return nil, fmt.Errorf("tx.Error: %w", tx.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
return historyEntries, nil
|
// Remove duplicate entries using EncryptedId as the key to save bandwidth when sending data to the client
|
||||||
|
uniqueEntries := make(map[string]*shared.EncHistoryEntry)
|
||||||
|
for _, entry := range historyEntries {
|
||||||
|
uniqueEntries[entry.EncryptedId] = entry
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the map back to a slice
|
||||||
|
dedupedEntries := make([]*shared.EncHistoryEntry, 0, len(uniqueEntries))
|
||||||
|
for _, entry := range uniqueEntries {
|
||||||
|
dedupedEntries = append(dedupedEntries, entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dedupedEntries, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) HistoryEntriesForDevice(ctx context.Context, deviceID string, limit int) ([]*shared.EncHistoryEntry, error) {
|
func (db *DB) HistoryEntriesForDevice(ctx context.Context, deviceID string, limit int) ([]*shared.EncHistoryEntry, error) {
|
||||||
|
@ -74,7 +74,6 @@ func (s *Server) apiSubmitHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) apiBootstrapHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) apiBootstrapHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// TODO: Update this to filter out duplicate entries
|
|
||||||
userId := getRequiredQueryParam(r, "user_id")
|
userId := getRequiredQueryParam(r, "user_id")
|
||||||
deviceId := getRequiredQueryParam(r, "device_id")
|
deviceId := getRequiredQueryParam(r, "device_id")
|
||||||
version := getHishtoryVersion(r)
|
version := getHishtoryVersion(r)
|
||||||
|
Loading…
Reference in New Issue
Block a user