From 6ed8cf0e07322fd78c41b22fc94c40dfa9c6d47a Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 3 Mar 2022 12:09:16 +0000 Subject: [PATCH] Handle `ErrNoRows` when sending read updates --- syncapi/consumers/clientapi.go | 5 +++-- syncapi/consumers/eduserver_receipts.go | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/syncapi/consumers/clientapi.go b/syncapi/consumers/clientapi.go index f01afce6d..fcb7b5b1c 100644 --- a/syncapi/consumers/clientapi.go +++ b/syncapi/consumers/clientapi.go @@ -16,6 +16,7 @@ package consumers import ( "context" + "database/sql" "encoding/json" "fmt" @@ -138,12 +139,12 @@ func (s *OutputClientDataConsumer) sendReadUpdate(ctx context.Context, userID st var readPos types.StreamPosition var fullyReadPos types.StreamPosition if output.ReadMarker.Read != "" { - if _, readPos, err = s.db.PositionInTopology(ctx, output.ReadMarker.Read); err != nil { + if _, readPos, err = s.db.PositionInTopology(ctx, output.ReadMarker.Read); err != nil && err != sql.ErrNoRows { return fmt.Errorf("s.db.PositionInTopology (Read): %w", err) } } if output.ReadMarker.FullyRead != "" { - if _, fullyReadPos, err = s.db.PositionInTopology(ctx, output.ReadMarker.FullyRead); err != nil { + if _, fullyReadPos, err = s.db.PositionInTopology(ctx, output.ReadMarker.FullyRead); err != nil && err != sql.ErrNoRows { return fmt.Errorf("s.db.PositionInTopology (FullyRead): %w", err) } } diff --git a/syncapi/consumers/eduserver_receipts.go b/syncapi/consumers/eduserver_receipts.go index 881583449..4e4c61c67 100644 --- a/syncapi/consumers/eduserver_receipts.go +++ b/syncapi/consumers/eduserver_receipts.go @@ -16,6 +16,7 @@ package consumers import ( "context" + "database/sql" "encoding/json" "fmt" @@ -129,7 +130,7 @@ func (s *OutputReceiptEventConsumer) sendReadUpdate(ctx context.Context, output } var readPos types.StreamPosition if output.EventID != "" { - if _, readPos, err = s.db.PositionInTopology(ctx, output.EventID); err != nil { + if _, readPos, err = s.db.PositionInTopology(ctx, output.EventID); err != nil && err != sql.ErrNoRows { return fmt.Errorf("s.db.PositionInTopology (Read): %w", err) } }