objectbox / objectbox/objectbox-java
Only re-deliver query results if results have changed
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.6k
- Forks
- 311
- PR merge metrics
- No merged PRs in 30d
Description
Code example probably will be best description here.
@Entity
class KAEntry(
@Unique val key: String,
val value: String,
@Id var id: Long = 0
)
class MyApp : Application() {
private lateinit var subs1: DataSubscription
private lateinit var subs2: DataSubscription
private lateinit var boxStore: BoxStore
private set
override fun onCreate() {
super.onCreate()
boxStore = MyObjectBox.builder().name("main").androidContext(this).build()
val box = boxStore.boxFor(KAEntry::class.java)
box.removeAll() // just for reproducibility, to avoid "unique constraint violation" on second run of app
subs1 = box.query().equal(KAEntry_.key, "key1")
.build().subscribe().observer { v ->
Log.i("MyApp", "triggered for key1" )
}
subs2 = box.query().equal(KAEntry_.key, "key2")
.build().subscribe().observer { v ->
Log.i("MyApp", "triggered for key2" )
}
box.put(KAEntry("key1","some value"))
}
}
Problem is that even I've only put "key1" object and therefore only first query should trigger it's observer - both actually get triggered:
2021-04-05 14:22:53.263 25926-25962/com.acme I/MyApp: triggered for key1
2021-04-05 14:22:53.263 25926-25963/com.acme I/MyApp: triggered for key2
Either I don't understand something or this observer on query actually bugged.
I can see that triggering observer for only those objects that are changed and are in query result may have some performance impact. Though even in this case I would like to have some way of detecting that change was made to objects that query returns and not any object of this type.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file, test, or entry point is named. Start by reproducing the Kotlin query-subscription example and then trace the query observer implementation and its tests, if present. Done means observers are notified only when their query results change, or the supported way to detect relevant object changes is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- databases, mobile-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100