Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding insertToRealm: a fast and more memory efficient way to copy data into Realm #1817

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public interface MutableRealm : TypedRealm {
*/
public fun <T : RealmObject> copyToRealm(instance: T, updatePolicy: UpdatePolicy = UpdatePolicy.ERROR): T

public fun <T : RealmObject> insertToRealm(instance: T, updatePolicy: UpdatePolicy = UpdatePolicy.ERROR)

public fun <T : RealmObject> insertToRealm(instances: Collection<T>, updatePolicy: UpdatePolicy = UpdatePolicy.ERROR)

/**
* Returns a [RealmQuery] matching the predicate represented by [query].
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ internal interface InternalMutableRealm : MutableRealm {
return copyToRealm(configuration.mediator, realmReference, instance, updatePolicy)
}

override fun <T : RealmObject> insertToRealm(instance: T, updatePolicy: UpdatePolicy) {
val cache: UnmanagedToManagedObjectPointerCache = mutableMapOf()

insertToRealm(realmReference, instance, updatePolicy, cache)

cache.forEach { it.value.release() }
cache.clear()
}

override fun <T : RealmObject> insertToRealm(instances: Collection<T>, updatePolicy: UpdatePolicy) {
val cache: UnmanagedToManagedObjectPointerCache = mutableMapOf()

insertToRealm(realmReference, instances, updatePolicy, cache)

cache.forEach { it.value.release() }
cache.clear()
}

override fun delete(deleteable: Deleteable) {
deleteable.asInternalDeleteable().delete()
}
Expand Down
Loading
Loading