Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<DbEventScope>

@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")
Comment thread
alexandr-simprints marked this conversation as resolved.
suspend fun loadClosed(type: EventScopeType): List<DbEventScope>

@Query("select * from DbEventScope where id = :scopeId order by start_unixMs desc limit 1")
Expand All @@ -30,4 +33,8 @@ internal interface SessionScopeRoomDao {

@Query("delete from DbEventScope")
suspend fun deleteAll()

object EventScopeConstants {
const val CLOSED_SCOPES_LIMIT = 50
}
}