Skip to content

Commit

Permalink
improve responsiveness of bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed Apr 16, 2024
1 parent 6329209 commit f9bbb43
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 105 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package fr.androidmakers.store.graphql

import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.http.HttpRequest
import com.apollographql.apollo3.api.http.HttpResponse
import com.apollographql.apollo3.cache.normalized.api.MemoryCacheFactory
import com.apollographql.apollo3.cache.normalized.normalizedCache
import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory
import com.apollographql.apollo3.network.http.HttpInterceptor
import com.apollographql.apollo3.network.http.HttpInterceptorChain
import fr.androidmakers.domain.repo.UserRepository

fun ApolloClient(
sqlNormalizedCacheFactory: SqlNormalizedCacheFactory,
userRepository: UserRepository,
): ApolloClient {
val memoryCacheFactory = MemoryCacheFactory(20_000_000).chain(sqlNormalizedCacheFactory)
return ApolloClient.Builder()
.serverUrl("https://androidmakers.fr/graphql")
.addHttpInterceptor(object : HttpInterceptor {
override suspend fun intercept(request: HttpRequest, chain: HttpInterceptorChain): HttpResponse {
return chain.proceed(
request.newBuilder()
.apply {
/**
*
*/
val token = userRepository.getIdToken()
if (token != null) {
addHeader("Authorization", "Bearer $token")
}
}
.build()
)
}
})
.normalizedCache(memoryCacheFactory)
.build()
}

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions shared/di/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ kotlin {
commonMain.dependencies {
implementation(project(":shared:domain"))
implementation(project(":shared:data"))
implementation(libs.apollo.normalized.cache.sqlite)

api(libs.koin.core)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package fr.androidmakers.di

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import fr.androidmakers.store.graphql.ApolloClientBuilder
import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory
import fr.androidmakers.store.graphql.ApolloClient
import fr.androidmakers.store.local.createDataStore
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module

actual val dataPlatformModule = module {
single {
ApolloClientBuilder(
androidContext(),
"https://androidmakers.fr/graphql",
"androidmakers2024",
ApolloClient(
SqlNormalizedCacheFactory(context = get()),
get()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import fr.androidmakers.domain.repo.SpeakersRepository
import fr.androidmakers.domain.repo.UserRepository
import fr.androidmakers.domain.repo.VenueRepository
import fr.androidmakers.store.firebase.FirebaseUserRepository
import fr.androidmakers.store.graphql.ApolloClientBuilder
import fr.androidmakers.store.graphql.PartnersGraphQLRepository
import fr.androidmakers.store.graphql.RoomsGraphQLRepository
import fr.androidmakers.store.graphql.SessionsGraphQLRepository
Expand All @@ -22,7 +21,6 @@ import org.koin.dsl.module
expect val dataPlatformModule: Module

val dataModule = module {
single { get<ApolloClientBuilder>().build() }
single<PartnersRepository> { PartnersGraphQLRepository(get()) }
single<RoomsRepository> { RoomsGraphQLRepository(get()) }
single<SessionsRepository> { SessionsGraphQLRepository(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package fr.androidmakers.di

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import fr.androidmakers.store.graphql.ApolloClientBuilder
import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory
import fr.androidmakers.store.graphql.ApolloClient
import fr.androidmakers.store.local.createDataStore
import kotlinx.cinterop.ExperimentalForeignApi
import org.koin.dsl.module
Expand All @@ -13,7 +14,12 @@ import platform.Foundation.NSUserDomainMask

@OptIn(ExperimentalForeignApi::class)
actual val dataPlatformModule = module {
single { ApolloClientBuilder("https://androidmakers.fr/graphql", "androidmakers2024", "") }
single {
ApolloClient(
SqlNormalizedCacheFactory(),
get()
)
}

single<DataStore<Preferences>> {
createDataStore {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ class SetSessionBookmarkUseCase(
private val bookmarksRepository: BookmarksRepository
) {
suspend operator fun invoke(sessionId: String, isBookmark: Boolean) {
bookmarksRepository.setBookmarked(sessionId, isBookmark)
userRepository.getUser()?.id?.let { token ->
sessionsRepository.setBookmark(token, sessionId, isBookmark)
sessionsRepository.setBookmark(token, sessionId, isBookmark)
}

bookmarksRepository.setBookmarked(sessionId, isBookmark)
}
}

0 comments on commit f9bbb43

Please sign in to comment.