aboutsummaryrefslogtreecommitdiff
path: root/syncapi
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-04-20 16:06:46 +0100
committerGitHub <noreply@github.com>2022-04-20 16:06:46 +0100
commitbb987cd64b118044a4f3351c377516813514ee19 (patch)
treeff90bea267a353f851412c434b392b86401fb053 /syncapi
parenta9f0a390c6e6efed9c09c72839960f57b5f3e5f2 (diff)
Lazy loading fixes (#2362)
* Return some more usefully wrapped errors when doing sync * Remove unnecessary error check * Couple of guards around `sql.ErrNoRows` * Nolint
Diffstat (limited to 'syncapi')
-rw-r--r--syncapi/streams/stream_pdu.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/syncapi/streams/stream_pdu.go b/syncapi/streams/stream_pdu.go
index ddc2f55c..0f11d55f 100644
--- a/syncapi/streams/stream_pdu.go
+++ b/syncapi/streams/stream_pdu.go
@@ -3,6 +3,7 @@ package streams
import (
"context"
"database/sql"
+ "fmt"
"sync"
"time"
@@ -205,6 +206,7 @@ func (p *PDUStreamProvider) IncrementalSync(
return newPos
}
+// nolint:gocyclo
func (p *PDUStreamProvider) addRoomDeltaToResponse(
ctx context.Context,
device *userapi.Device,
@@ -228,13 +230,16 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
eventFilter, true, true,
)
if err != nil {
- return r.From, err
+ if err == sql.ErrNoRows {
+ return r.To, nil
+ }
+ return r.From, fmt.Errorf("p.DB.RecentEvents: %w", err)
}
recentEvents := p.DB.StreamEventsToEvents(device, recentStreamEvents)
delta.StateEvents = removeDuplicates(delta.StateEvents, recentEvents) // roll back
prevBatch, err := p.DB.GetBackwardTopologyPos(ctx, recentStreamEvents)
if err != nil {
- return r.From, err
+ return r.From, fmt.Errorf("p.DB.GetBackwardTopologyPos: %w", err)
}
// If we didn't return any events at all then don't bother doing anything else.
@@ -268,15 +273,12 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
}
if stateFilter.LazyLoadMembers {
- if err != nil {
- return r.From, err
- }
delta.StateEvents, err = p.lazyLoadMembers(
ctx, delta.RoomID, true, limited, stateFilter.IncludeRedundantMembers,
device, recentEvents, delta.StateEvents,
)
- if err != nil {
- return r.From, err
+ if err != nil && err != sql.ErrNoRows {
+ return r.From, fmt.Errorf("p.lazyLoadMembers: %w", err)
}
}