Skip to content

Commit 18cdfcb

Browse files
committed
reduce tx scope
1 parent 9891780 commit 18cdfcb

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

video/tasks/synchronize_with_livekit.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,28 @@ func (srv *SynchronizeWithLivekitService) DoJob() {
5757
}
5858

5959
func (srv *SynchronizeWithLivekitService) cleanOrphans(ctx context.Context) {
60-
err := db.Transact(srv.database, func(tx *db.Tx) error {
61-
offset := int64(0)
62-
hasMoreElements := true
63-
for hasMoreElements {
60+
offset := int64(0)
61+
hasMoreElements := true
62+
for hasMoreElements {
63+
err := db.Transact(srv.database, func(tx *db.Tx) error {
6464
// here we use order by owner_id
6565
batchUserStates, err := tx.GetAllUserStates(utils.DefaultSize, offset)
6666
if err != nil {
6767
GetLogEntry(ctx).Errorf("error during reading user states %v", err)
68-
continue
68+
return err
6969
}
7070
srv.processBatch(ctx, tx, batchUserStates)
7171

7272
hasMoreElements = len(batchUserStates) == utils.DefaultSize
7373
offset += utils.DefaultSize
74+
75+
return nil
76+
})
77+
78+
if err != nil {
79+
GetLogEntry(ctx).Errorf("error during processing: %v", err)
80+
continue
7481
}
75-
return nil
76-
})
77-
if err != nil {
78-
GetLogEntry(ctx).Errorf("Error during processing: %v", err)
7982
}
8083
}
8184

0 commit comments

Comments
 (0)