Skip to content

Commit

Permalink
feat: clean offline progress when logging out
Browse files Browse the repository at this point in the history
  • Loading branch information
PavloNetrebchuk committed Jul 18, 2024
1 parent 2939fe1 commit bab3839
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/org/openedx/app/room/DatabaseManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DatabaseManager(
CoroutineScope(Dispatchers.Main).launch {
courseDao.clearCachedData()
dashboardDao.clearCachedData()
downloadDao.clearCachedData()
downloadDao.clearOfflineProgress()
discoveryDao.clearCachedData()
}
}
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/org/openedx/core/module/db/CalendarDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import org.openedx.core.data.model.room.CourseCalendarEventEntity
import org.openedx.core.data.model.room.CourseCalendarStateEntity

Expand Down Expand Up @@ -55,4 +56,10 @@ interface CalendarDao {
checksum: Int? = null,
isCourseSyncEnabled: Boolean? = null
)

@Transaction
suspend fun clearCachedData() {
clearCourseCalendarStateCachedData()
clearCourseCalendarEventsCachedData()
}
}
6 changes: 3 additions & 3 deletions core/src/main/java/org/openedx/core/module/db/DownloadDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ interface DownloadDao {
@Query("DELETE FROM download_model WHERE id in (:ids)")
suspend fun removeAllDownloadModels(ids: List<String>)

@Query("DELETE FROM download_model")
suspend fun clearCachedData()

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertOfflineXBlockProgress(offlineXBlockProgress: OfflineXBlockProgress)

Expand All @@ -46,4 +43,7 @@ interface DownloadDao {

@Query("DELETE FROM offline_x_block_progress_table WHERE id in (:ids)")
suspend fun removeOfflineXBlockProgress(ids: List<String>)

@Query("DELETE FROM offline_x_block_progress_table")
suspend fun clearOfflineProgress()
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package org.openedx.core.repository

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import org.openedx.core.data.api.CourseApi
import org.openedx.core.data.model.room.CourseCalendarEventEntity
import org.openedx.core.data.model.room.CourseCalendarStateEntity
Expand Down Expand Up @@ -55,12 +51,7 @@ class CalendarRepository(
}

suspend fun clearCalendarCachedData() {
CoroutineScope(Dispatchers.Main).launch {
val clearCourseCalendarStateDeferred = async { calendarDao.clearCourseCalendarStateCachedData() }
val clearCourseCalendarEventsDeferred = async { calendarDao.clearCourseCalendarEventsCachedData() }
clearCourseCalendarStateDeferred.await()
clearCourseCalendarEventsDeferred.await()
}
calendarDao.clearCachedData()
}

suspend fun updateCourseCalendarStateByIdInCache(
Expand Down

0 comments on commit bab3839

Please sign in to comment.