feat(sync): paginate Android sync with change tokens
This commit is contained in:
1 parent
0ff94f9b10
commit
97c237be80
76 files changed
+3401
-851
No files matched your search
+14
-6
@@ -11,22 +11,26 @@ import (
|
||||
)
|
||||
|
||||
func (s *Server) handleWebData(w http.ResponseWriter, r *http.Request) {
|
||||
lists, err := s.db.queryLists(r.Context(), false, nil)
|
||||
s.writeWebData(w, r, requestUserID(r))
|
||||
}
|
||||
|
||||
func (s *Server) writeWebData(w http.ResponseWriter, r *http.Request, userID int64) {
|
||||
lists, err := s.db.queryLists(r.Context(), userID, false, nil)
|
||||
if err != nil {
|
||||
writeJSONError(w, http.StatusInternalServerError, "Failed to fetch data")
|
||||
return
|
||||
}
|
||||
fields, err := s.db.queryFields(r.Context(), false, nil, "")
|
||||
fields, err := s.db.queryFields(r.Context(), userID, false, nil, "")
|
||||
if err != nil {
|
||||
writeJSONError(w, http.StatusInternalServerError, "Failed to fetch data")
|
||||
return
|
||||
}
|
||||
items, err := s.db.queryItems(r.Context(), false, nil, "")
|
||||
items, err := s.db.queryItems(r.Context(), userID, false, nil, "")
|
||||
if err != nil {
|
||||
writeJSONError(w, http.StatusInternalServerError, "Failed to fetch data")
|
||||
return
|
||||
}
|
||||
values, err := s.db.queryValues(r.Context(), nil, "")
|
||||
values, err := s.db.queryValues(r.Context(), userID, nil, "")
|
||||
if err != nil {
|
||||
writeJSONError(w, http.StatusInternalServerError, "Failed to fetch data")
|
||||
return
|
||||
@@ -134,10 +138,14 @@ func (s *Server) handleNotificationPoll(w http.ResponseWriter, r *http.Request)
|
||||
SELECT id, deviceidorigin, eventtype, entitytype, entityid, listid, createdat
|
||||
FROM notifications
|
||||
WHERE createdat > $1
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM list_memberships m
|
||||
WHERE m.listid = notifications.listid AND m.user_id = $2
|
||||
)
|
||||
`
|
||||
args := []any{since}
|
||||
args := []any{since, requestUserID(r)}
|
||||
if deviceID != "" {
|
||||
query += ` AND (deviceidorigin IS NULL OR deviceidorigin <> $2)`
|
||||
query += ` AND (deviceidorigin IS NULL OR deviceidorigin <> $3)`
|
||||
args = append(args, deviceID)
|
||||
}
|
||||
query += ` ORDER BY createdat ASC LIMIT 500`
|
||||
|
||||
Reference in new issue
Block a user