From 21230cf3659eeb236301951590460de42dfbe27f Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Tue, 31 Mar 2026 23:37:39 +0200 Subject: [PATCH] Prep inMemory database --- .../builder/PlatformDatabaseBuilder.android.kt | 6 ++++++ .../database/builder/PlatformDatabaseBuilder.kt | 2 ++ .../ac/aux/compose/managers/DatabaseManager.kt | 14 ++++++++++++++ .../ac/aux/compose/ui/composable/FeedScreen.kt | 1 - .../compose/ui/composable/navigation/AuxNavHost.kt | 3 +++ .../builder/PlatformDatabaseBuilder.ios.kt | 4 ++++ .../builder/PlatformDatabaseBuilder.jvm.kt | 4 ++++ 7 files changed, 33 insertions(+), 1 deletion(-) diff --git a/composeApp/src/androidMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.android.kt b/composeApp/src/androidMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.android.kt index c2bfa3af..51397e17 100644 --- a/composeApp/src/androidMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.android.kt +++ b/composeApp/src/androidMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.android.kt @@ -15,4 +15,10 @@ actual object PlatformDatabaseBuilder { name = dbFile.absolutePath ) } + + actual fun getInMemoryDatabaseBuilder(platform: PlatformContext): RoomDatabase.Builder { + return Room.inMemoryDatabaseBuilder( + context = platform.applicationContext + ) + } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.kt index 5b0bc1c5..8ddc7bc5 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.kt @@ -9,6 +9,8 @@ import kotlinx.coroutines.IO expect object PlatformDatabaseBuilder { fun getDatabaseBuilder(platformContext: PlatformContext): RoomDatabase.Builder + + fun getInMemoryDatabaseBuilder(platform: PlatformContext): RoomDatabase.Builder } fun getRoomDatabase( diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/managers/DatabaseManager.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/managers/DatabaseManager.kt index 5fe082f6..a956509d 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/managers/DatabaseManager.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/managers/DatabaseManager.kt @@ -4,6 +4,7 @@ import ac.aux.compose.AuxGlobal import ac.aux.compose.database.AuxDatabaseConstructor import ac.aux.compose.database.builder.PlatformDatabaseBuilder import ac.aux.compose.database.builder.getRoomDatabase +import androidx.room.Room class DatabaseManager( auxGlobal: AuxGlobal @@ -15,4 +16,17 @@ class DatabaseManager( ) ) } + + /** + * Dynamic data like user feeds and the likes will be in a in-memory db. + * + * We may also decide to just use the normal DB and manage what's saved better... + */ + val inMemoryAuxDatabase by lazy { + getRoomDatabase( + PlatformDatabaseBuilder.getInMemoryDatabaseBuilder( + auxGlobal.platformContext + ) + ) + } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/FeedScreen.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/FeedScreen.kt index 634b869b..a19ee6b6 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/FeedScreen.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/FeedScreen.kt @@ -127,7 +127,6 @@ fun FeedScreen( horizontalAlignment = Alignment.CenterHorizontally ) { stickyHeader { - Surface() { Row( modifier = Modifier.fillMaxWidth().padding(10.dp) diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/navigation/AuxNavHost.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/navigation/AuxNavHost.kt index 0d8284ae..c1481843 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/navigation/AuxNavHost.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/navigation/AuxNavHost.kt @@ -68,6 +68,9 @@ fun AuxNavHost( val nostrRepository = DatabaseNostrRepository( database = databaseManager.auxDatabase ) + val inMemoryNostrRepository = DatabaseNostrRepository( + database = databaseManager.inMemoryAuxDatabase + ) val exceptionHandler = CoroutineExceptionHandler { _, throwable -> diff --git a/composeApp/src/iosMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.ios.kt b/composeApp/src/iosMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.ios.kt index 6f38b667..ad88c156 100644 --- a/composeApp/src/iosMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.ios.kt +++ b/composeApp/src/iosMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.ios.kt @@ -29,4 +29,8 @@ actual object PlatformDatabaseBuilder { return requireNotNull(documentDirectory?.path) } + actual fun getInMemoryDatabaseBuilder(platform: PlatformContext): RoomDatabase.Builder { + return Room.inMemoryDatabaseBuilder() + } + } \ No newline at end of file diff --git a/composeApp/src/jvmMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.jvm.kt b/composeApp/src/jvmMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.jvm.kt index 683d4ec3..eebd7b28 100644 --- a/composeApp/src/jvmMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.jvm.kt +++ b/composeApp/src/jvmMain/kotlin/ac/aux/compose/database/builder/PlatformDatabaseBuilder.jvm.kt @@ -13,4 +13,8 @@ actual object PlatformDatabaseBuilder { name = dbFile.absolutePath, ) } + + actual fun getInMemoryDatabaseBuilder(platform: PlatformContext): RoomDatabase.Builder { + return Room.inMemoryDatabaseBuilder() + } } \ No newline at end of file