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

Support observing changes to single properties #1027

Open
NBXXF opened this issue Nov 23, 2021 · 14 comments
Open

Support observing changes to single properties #1027

NBXXF opened this issue Nov 23, 2021 · 14 comments
Labels
enhancement New feature or request

Comments

@NBXXF
Copy link

NBXXF commented Nov 23, 2021

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有提供

@NBXXF NBXXF added the enhancement New feature or request label Nov 23, 2021
@greenrobot-team greenrobot-team changed the title 希望支持自定义模型来查询 比如存储模型是A 我希望用B 来接受 B只有A的一些同名字段 来保证内存开销 I hope to support a custom model to query. For example, the storage model is A. I want to use B to accept B. Only some fields with the same name of A to ensure memory overhead Nov 29, 2021
@greenrobot-team
Copy link
Member

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

@greenrobot-team greenrobot-team added the more info required Further information is requested label Nov 29, 2021
@NBXXF
Copy link
Author

NBXXF commented Nov 30, 2021

@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.

@no-response no-response bot removed the more info required Further information is requested label Nov 30, 2021
@greenrobot-team
Copy link
Member

greenrobot-team commented Nov 30, 2021

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
Copy link
Author

NBXXF commented Mar 19, 2022

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
Copy link
Author

NBXXF commented Mar 19, 2022

每个模型数据极大 字段极多,我希望按照某种条件去观察他们 提供返回值只有一个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
Copy link
Member

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
Copy link
Author

NBXXF commented Mar 22, 2022

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

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

@greenrobot-team greenrobot-team changed the title I hope to support a custom model to query. For example, the storage model is A. I want to use B to accept B. Only some fields with the same name of A to ensure memory overhead Support observing changes to single properties Mar 22, 2022
@greenrobot-team
Copy link
Member

greenrobot-team commented Mar 22, 2022

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
Copy link
Author

NBXXF commented Mar 23, 2022

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
Copy link

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
Copy link

+1,Good idea

@xiangning17
Copy link

+1, I also need this feature

@NBXXF
Copy link
Author

NBXXF commented Mar 26, 2022

如果监听的时候可以设置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
Copy link
Author

NBXXF commented Mar 26, 2022

我发现特别有意思的东西 这个监听并不是真正意义上的监听
比如我监听条件写的是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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants