objectbox-java icon indicating copy to clipboard operation
objectbox-java copied to clipboard

Modify ToMany without loading all relation entities

Open greenrobot opened this issue 7 years ago • 2 comments

Currently, when you operate on a ToMany, an add or remove loads all entities.

Alternatively we should also have means to modify to-many relations without loading everything to avoid bloating memory (e.g. #392).

Ways to do it:

  1. Make ToMany lazy when it come to add and remove
  2. Provide methods to update relations outside of ToMany
  3. ?

greenrobot avatar Jul 25 '18 14:07 greenrobot

Also think about only loading IDs instead of the whole entity. https://stackoverflow.com/q/54821446/9187282

greenrobot-team avatar Feb 25 '19 12:02 greenrobot-team

This is a critical feature that's desperately needed.

In my sense, the current ToMany relations are pretty controversial. On the one hand it is convenient, makes the code more elegant, and for accessing a small number of records, it's quick enough. But on the other hand, It takes too much memory and is too slow for bulk processing (creating, accessing, clearing relations, and removing large number of records). The add method is very expensive. It's nearly prohibitive to call it progressively. One has to call addAll (if that's affordable) for create the relations once and for all.

XilinJia avatar Mar 07 '21 10:03 XilinJia