Daniel
03/09/2023, 6:22 PMstruct LoginView: View {
@State var userId : String = ""
@State var password : String = ""
@State var myUser = UserInfo()
var repo = RealmRepo()
var body: some View {
NavigationView{
VStack(){
TextField("Username", text: $userId)
TextField("Password", text: $password)
Button("Login"){
repo.login(email: $userId.wrappedValue, password: $password.wrappedValue) { user, error in
if(user != nil){
self.repo.getUserProfile().watch(block: {items in
self.myUser = items as! UserInfo
})
}
}
}
}
}
}
}
I do the login, and if the login is ok, I get the profile of the user.
My realm repo:
suspend fun login(email: String, password: String): User {
return appService.login(Credentials.emailPassword(email, password))
}
fun getUserProfile(): CommonFlow<UserInfo?> {
val userId = appService.currentUser!!.id
val user = realm.query<UserInfo>("_id = $0", userId).asFlow().map {
it.list.firstOrNull()
}.asCommonFlow()
return user
}
private val appService by lazy {
val appConfiguration =
AppConfiguration.Builder(appId = "xxxx").log(LogLevel.ALL).build()
App.create(appConfiguration)
}
private val realm by lazy {
val user = appService.currentUser!!
val config =
SyncConfiguration.Builder(user, schemaClass).name("xxxx").schemaVersion(1)
.initialSubscriptions { realm ->
add(realm.query<UserInfo>(), name = "user info", updateExisting = true)
}.waitForInitialRemoteData().build()
Realm.open(config)
}
When I do the login, will print 2 times the log: INFO: [REALM] Realm opened: /var/mobile/
How is this possible?
Is it because the the login block? Should I make the login and getUserProfile calls in a different way?Paolo Rotolo
03/10/2023, 2:47 PMdefault.realm
reached 17 GB in one of our apps, even if we don't store a lot of data (there are very frequent writes, but then entities are deleted when in sync with server). We noticed a similar problem on github, so we upgraded realm version to latest one.
Now we're tracking the numberOfActiveVersions
on each write, and we see that the number increases each time a new write is performed (1 write for second). It should be related to this issue: https://github.com/realm/realm-kotlin/issues/1081
We're still performing more tests with latest realm 1.6.1
but, will this issue of always growing realm versions affect database size on disk?
According to github, https://github.com/realm/realm-core/pull/5440 (Fsa/new version management) was merged in latest release, is there a way we can mitigate active versions growing with this new version management?
Thanks in advance.Daniel
03/10/2023, 7:15 PMRanjith
03/16/2023, 2:10 AMDaniel
03/25/2023, 8:08 PMDaniel
04/07/2023, 6:55 PMDaniel
04/07/2023, 7:27 PMSyncSession.downloadAllServerChange()
and SyncSession.uploadAllLocalChanges()
was reversed.
What is the meaning of reversed in this case?John O'Reilly
04/15/2023, 8:54 AMYacov Rosenberg
04/28/2023, 4:42 PM@Provides
@Singleton
fun provideLocalRealm(config: RealmConfiguration): Realm {
return Realm.open(config)
}
And inject it in my use cases...
But I'm receiveing a error
java.lang.IllegalStateException: Scoped provider was invoked recursively returning different results: RealmImpl[/data/user/0/ee.visittallinn.tallinncard.dev/files/REALM_LOCAL}] & RealmImpl[/data/user/0/ee.visittallinn.tallinncard.dev/files/REALM_LOCAL}]. This is likely due to a circular dependency.
As I understood from documentation we could open the realm once and keep it as a singleton in the application lifecycle.
Or I should open every time I need to use it and only inject the RealmConfiguration...?chrmelchior
05/01/2023, 10:08 AMSlackbot
05/17/2023, 3:08 PMJohn O'Reilly
05/24/2023, 5:54 PMchrmelchior
05/25/2023, 11:09 AMThiago Delgado
06/09/2023, 1:40 PMChristos Savlidis
07/27/2023, 1:51 PMRealm.open(getRealmUnEncryptedConfig())
every time is correctGrzegorz Gajewski
07/28/2023, 2:14 PMThe Kotlin SDK does not provide the ability to set and access a default realm in your application. Since you can now share realms, objects, and results across threads, you can rely on a global singleton instead.
So I went with global singleton. But I don’t think this works like I thought it would (similar to room) as now I’m getting:
java.lang.IllegalStateException: [RLM_ERR_WRONG_TRANSACTION_STATE]: The Realm is already in a write transaction
I have a background sync that might write at any given moment, should I open another Realm for that in this case to avoid this crash?John O'Reilly
07/30/2023, 12:16 PMDaniel
07/31/2023, 7:56 PMappService.currentUser
is null for some users after they already login?
this will cause the app to crash because I really dont know a good way or flow to handle when it is null, I dont even know how its possible to be null, because I do not delete the users nor the token refresh expires.
the code:
fun getUserProfile(): CommonFlow<UserInfo?> {
val userId = appService.currentUser!!.id
val user = realm.query<UserInfo>("_id = $0", userId).asFlow().map {
it.list.firstOrNull()
}.asCommonFlow()
return user
}
how is it possible to be null?Grzegorz Gajewski
08/01/2023, 7:23 AMOR
between two subqueries? I have a big query with subqueries build like this:
var query = query<Model>("id == $0", id)
if (otherModelId != null) {
query = query.query("otherModel.id == $0", otherModelId)
}
if (markedOnly) {
query = query("flagged == $0", true)
}
And now I need to add OR to the top level query.Thiago Delgado
08/09/2023, 11:17 PMGrzegorz Gajewski
08/10/2023, 9:26 AMThiago Delgado
08/10/2023, 8:45 PMGrzegorz Gajewski
08/25/2023, 11:30 AM1.7.0
and latest 1.10.2
. When I remove the code to collect the flow and run GC manually it drops (but only in 1.7.0
). What am I missing here? What are the strategies that we can use today to keep active realm versions low?
object Singleton {
val config = RealmConfiguration.create(schema = setOf(Item::class))
val realm = Realm.open(config)
}
class Item : RealmObject {
@PrimaryKey
var _id: ObjectId = ObjectId()
var isComplete: Boolean = false
var summary: String = ""
var owner_id: String = ""
}
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val objectsCount = mutableStateOf(0L)
val versionsCount = mutableStateOf(realm.getNumberOfActiveVersions())
setContent {
RealmTestTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting(objectsCount.value.toString(), versionsCount.value.toString(), onClick = {
lifecycleScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
repeat(100) {
realm.write {
copyToRealm(Item().apply {
summary = "Do the laundry"
isComplete = false
})
}
delay(10)
versionsCount.value = realm.getNumberOfActiveVersions()
}
}
})
}
}
}
realm
.query<Item>()
.asFlow()
.onEach {
val summaries = it.list.map { it.summary }
objectsCount.value = summaries.count().toLong()
}
.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
.launchIn(lifecycleScope)
}
}
@Composable
fun Greeting(objectsCount: String, activeVersions: String, modifier: Modifier = Modifier, onClick: () -> Unit) {
Column() {
Text(
text = "Objects $objectsCount",
modifier = modifier
)
Text(
text = "Active versions $activeVersions",
modifier = modifier
)
Button(onClick = onClick) {
Text(text = "Insert 100 items")
}
}
}
benkuly
10/12/2023, 3:20 PMdephinera
10/17/2023, 8:23 AMChristopher Mederos
10/20/2023, 12:54 AM"progressMinutes > $0 AND assignee == $1", 1, "Alex"
Ideally, is there a similar syntax available like "progressMinutes > $0 AND assignee == $1", queryParams.values
?BaBeStudios
11/08/2023, 12:07 PMCaused by: java.lang.ClassNotFoundException: Didn't find class "java.time.Clock" on path: DexPathList[[zip file "/data/app/[...]split_config.xxxhdpi.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
java.lang.ClassLoader.loadClass(ClassLoader.java:380)
java.lang.ClassLoader.loadClass(ClassLoader.java:312)
io.realm.kotlin.internal.platform.SystemUtilsKt.currentTime(SystemUtils.kt:32)
io.realm.kotlin.types.RealmInstant$Companion.now(RealmInstant.kt:87)
Clock was added in API 26 for Android. Is there a way to mitigate this, or is the minimum Android SDK version for the Kotlin SDK effectively API level 26? I'm writing this before looking into replacing RealmInstant or the call to systemUTC(), that causes the Exception.chrmelchior
12/04/2023, 1:26 PMChristopher Mederos
12/20/2023, 6:18 AMDaniel
02/07/2024, 11:31 PMsuspend fun getRestaurantsProcessedOrdersWithThrowAndroid(): CommonFlow<List<ProcessedOrder>> {
realm.syncSession.downloadAllServerChanges()
val userId = appService.currentUser
if(appService.currentUser != null) {
val restaurantsIds = realm.query<Restaurant>("userID = $0", userId!!.id).find().map { it.getID() }
val queryValues = restaurantsIds.joinToString(separator = ",", prefix = "{", postfix = "}")
return realm.query<ProcessedOrder>(
"restaurantID IN $0", queryValues
).asFlow()
.map {
it.list
}.asCommonFlow()
}
else{
throw Exception("user not logged in")
}
}
I have tried with listOf("id,"id","id")...
Do you know why?