objectbox / objectbox-java

Android Database - first and fast, lightweight on-device vector database
https://objectbox.io
Apache License 2.0
4.35k stars 300 forks source link

Support observing changes to single properties #1027

Open NBXXF opened 2 years ago

NBXXF commented 2 years ago

Translation: I hope to support custom models to query. For example, the storage model is A. I want to use B to accept only some fields of the same name of A to ensure memory overhead. For example, when I do tabular data, I want to query some fields of model A (due to model A There are more than 20 fields) I only want to monitor some of the fields in this model. The current monitoring is full, which will result in a complete model of 20,000 data observations and 200,000 data. For example, I only want to monitor changes and get this Twenty thousand ids, then 20,000 complete model objects will not be generated. This function room provides

Original issue: 希望支持自定义模型来查询 比如存储模型是A 我希望用B 来接受 B只有A的一些同名字段 来保证内存开销

希望支持自定义模型来查询 比如存储模型是A 我希望用B 来接受 B只有A的一些同名字段 来保证内存开销 比如我在做表格数据的时候 希望查询出模型A的部分字段(由于模型A的字段已经超过20个) 我只想监听 这个模型中的部分字段 目前的监听 是全量的 会导致有2万条数据 观察返回也返回了20万条数据的完整模型 比如我只想监听改变而得到这两万个id,那么不会产生2万个完整的模型对象 这个功能room有提供

greenrobot-team commented 2 years ago

Are you suggesting partial objects? Then please vote for #348

NBXXF commented 2 years ago

@greenrobot-team 如果用findLazy 那么久不能用监听 我是想在监听的时候避免内存开销

Translation: If I use findLazy, I can’t use monitoring for a long time. I want to avoid memory overhead when I’m monitoring.

greenrobot-team commented 2 years ago

If I understand correctly, you can do this using ObjectBoxDataSource and the Android Paging library: https://docs.objectbox.io/android/paging-architecture-components#using-objectboxdatasource

But you can also build your own solution using query offset and limit plus a query observer that re-runs the query.

Edit: here is the implementation of ObjectBoxDataSource for inspiration: https://gist.github.com/greenrobot-team/4dbcd77fb8c77fce6499834bce8ec815

NBXXF commented 2 years ago
image

RxQuery 的返回值 只需要一个信号 而不是指定条件全量的数据(指定条件的全量数据并不是我想要的,极大),我需要按照这个信号 重新递归查询,不能直接获取这些数据来给业务

Translated: The return value of RxQuery only needs a signal instead of the full amount of data for the specified condition (the full amount of data for the specified condition is not what I want, it is very large), I need to re-recursive query according to this signal, I cannot directly obtain the data to give to the business

NBXXF commented 2 years ago

每个模型数据极大 字段极多,我希望按照某种条件去观察他们 提供返回值只有一个bool值 而不是全量数据, 那么我通过这个bool值 再从新去其他地方获取到想要的数据(比如树 是深度递归查询出来的) 如果观察返回对应观察的数据那这个数据量极大 也不一定是我想要的 而且还造成卡顿

Translation: The data of each model is very large and there are many fields. I want to observe them according to certain conditions. Provide the return value with only one bool value instead of full data, then I pass this bool value Then go to another place to get the desired data (for example, the tree is deeply recursively queried). If the observation returns the data corresponding to the observation, the amount of data is not necessarily what I want, and it also causes lag.

greenrobot-team commented 2 years ago

Then maybe just subscribe to changes in a Box (this is what the query subscription does internally). E.g.

boxStore.subscribe(Note::class.java).observer {
    // Data in Note box has changed.
}

https://docs.objectbox.io/data-observers-and-rx#observing-general-changes

NBXXF commented 2 years ago

这个粒度又太大了 ,很多没必要的刷新都要产生

Translation: This granularity is too large, and many unnecessary refreshes will be generated.

greenrobot-team commented 2 years ago

Alright, renamed the title and keeping this as a feature request then. For anyone interested, please thumbs up the first post!

Note these related feature requests:

NBXXF commented 2 years ago

Alright, renamed the title and keeping this as a feature request then. For anyone interested, please thumbs up the first post!

Note these related feature requests:

您好,能否快速支持一下呢?我现在app 卡在性能优化这块,十分感谢 Hello, can you give me quick support? I am now stuck in the performance optimization of the app. Thank you very much

wenjinfu321 commented 2 years ago
image

RxQuery 的返回值 只需要一个信号 而不是指定条件全量的数据(指定条件的全量数据并不是我想要的,极大),我需要按照这个信号 重新递归查询,不能直接获取这些数据来给业务 Translated: The return value of RxQuery only needs a signal instead of the full amount of data for the specified condition (the full amount of data for the specified condition is not what I want, it is very large), I need to re-recursive query according to this signal, I cannot directly obtain the data to give to the business

i need too

panzhenglian commented 2 years ago

+1,Good idea

xiangning17 commented 2 years ago

+1, I also need this feature

NBXXF commented 2 years ago

如果监听的时候可以设置limit offset 也可以

If you can set limit offset when listening, you can also set it

如果监听的时候可以设置limit offset 也可以

If you can set limit offset when listening, you can also set it

NBXXF commented 2 years ago

我发现特别有意思的东西 这个监听并不是真正意义上的监听 比如我监听条件写的是age<20, 那么我插入 age=21 的数据 之前的监听依旧收到了 只不过是按原来的查询条件重新查询了一次

I found something very interesting. This monitoring is not really monitoring

For example, if my listening condition is age < 20, the listening before I insert the data with age = 21 still receives, but it is queried again according to the original query condition