Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4655a7f1 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Merge branch '2687-t-work-on-cache' into 'main'

Improve AppLounge caching for Exodus Privacy

See merge request !491
parents 9e00d5b1 5db02e41
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package foundation.e.apps.data.exodus

import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Path
import retrofit2.http.Query

@@ -9,11 +10,14 @@ interface ExodusTrackerApi {

    companion object {
        const val BASE_URL = "https://exodus.ecloud.global/api/"
        const val CACHE_DURATION_SECONDS = 86400 // 1 day
    }

    @Headers("Cache-Control: public, max-age=$CACHE_DURATION_SECONDS")
    @GET("trackers")
    suspend fun getTrackerList(@Query("date") date: String): Response<Trackers>

    @Headers("Cache-Control: public, max-age=$CACHE_DURATION_SECONDS")
    @GET("search/{appHandle}/details")
    suspend fun getTrackerInfoOfApp(
        @Path("appHandle") appHandle: String,
+4 −0
Original line number Diff line number Diff line
@@ -56,6 +56,10 @@ class AppPrivacyInfoRepositoryImpl @Inject constructor(
            return Result.success(appInfo)
        }

        if (application.is_pwa) {
            return Result.error("No need to fetch trackers for a PWA app")
        }

        val appTrackerInfoResult = getResult {
            exodusTrackerApi.getTrackerInfoOfApp(
                appHandle,
+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ object CommonUtilsModule {
    @Singleton
    @Provides
    fun provideCache(@ApplicationContext context: Context): Cache {
        val cacheSize = (10 * 1024 * 1024).toLong() // 10 MB
        val cacheSize = (30 * 1024 * 1024).toLong() // 30 MB
        return Cache(context.cacheDir, cacheSize)
    }

+18 −3
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ class AppPrivacyInfoRepositoryImplTest {
            name = "Demo Three",
            package_name = "foundation.e.demothree",
            latest_version_code = 123,
            is_pwa = true,
            is_pwa = false,
        )
        val result = appPrivacyInfoRepository.getAppPrivacyInfo(application, application.package_name)
        assertEquals("getAppPrivacyInfo", true, result.isSuccess())
@@ -78,7 +78,7 @@ class AppPrivacyInfoRepositoryImplTest {
            name = "Demo Three",
            package_name = "",
            latest_version_code = 123,
            is_pwa = true,
            is_pwa = false,
        )
        val result = appPrivacyInfoRepository.getAppPrivacyInfo(application, application.package_name)
        assertEquals("getAppPrivacyInfo", false, result.isSuccess())
@@ -92,10 +92,25 @@ class AppPrivacyInfoRepositoryImplTest {
            name = "Demo Three",
            package_name = "a.b.c",
            latest_version_code = 123,
            is_pwa = true,
            is_pwa = false,
        )
        fakeTrackerDao.trackers.clear()
        val result = appPrivacyInfoRepository.getAppPrivacyInfo(application, application.package_name)
        assertEquals("getAppPrivacyInfo", 2, result.data?.trackerList?.size)
    }

    @Test
    fun getAppPrivacyInfoWhenIsPwa() = runTest {
        val application = Application(
            _id = "113",
            status = Status.UNAVAILABLE,
            name = "Demo Three",
            package_name = "a.b.c",
            latest_version_code = 123,
            is_pwa = true,
        )
        val result = appPrivacyInfoRepository.getAppPrivacyInfo(application, application.package_name)
        assertEquals(false, result.isSuccess())
        assertEquals("No need to fetch trackers for a PWA app", result.message)
    }
}