diff --git a/infra/events/src/main/java/com/simprints/infra/events/event/local/SessionScopeRoomDao.kt b/infra/events/src/main/java/com/simprints/infra/events/event/local/SessionScopeRoomDao.kt index 14c1379566..232fed09ed 100644 --- a/infra/events/src/main/java/com/simprints/infra/events/event/local/SessionScopeRoomDao.kt +++ b/infra/events/src/main/java/com/simprints/infra/events/event/local/SessionScopeRoomDao.kt @@ -5,6 +5,7 @@ import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import com.simprints.infra.events.event.domain.models.scope.EventScopeType +import com.simprints.infra.events.event.local.SessionScopeRoomDao.EventScopeConstants.CLOSED_SCOPES_LIMIT import com.simprints.infra.events.event.local.models.DbEventScope @Dao @@ -13,7 +14,9 @@ internal interface SessionScopeRoomDao { @Query("select * from DbEventScope where type = :type AND end_unixMs IS NULL order by start_unixMs desc") suspend fun loadOpen(type: EventScopeType): List - @Query("select * from DbEventScope where type = :type AND end_unixMs IS NOT NULL order by start_unixMs desc") + // Work around for loading too many scopes which cause upsync workers get stuck + // To limit the number of scopes loaded, we only load the last 50 closed scopes + @Query("select * from DbEventScope where type = :type AND end_unixMs IS NOT NULL order by start_unixMs desc limit $CLOSED_SCOPES_LIMIT") suspend fun loadClosed(type: EventScopeType): List @Query("select * from DbEventScope where id = :scopeId order by start_unixMs desc limit 1") @@ -30,4 +33,8 @@ internal interface SessionScopeRoomDao { @Query("delete from DbEventScope") suspend fun deleteAll() + + object EventScopeConstants { + const val CLOSED_SCOPES_LIMIT = 50 + } }