dimanche 14 février 2016

Model / View: Filtering data beforehand in database or at runtime in proxy model?

Imagine an applications that displays data from a sqlite database. The app is making use of model/view programming. It can have multiple views acting in parallel on different subsets of the same data (subsets made by filtering the required data types).

(Sidenote: I am using Qt, so there is no controller part, of course, but I did not find a more suitable tag.)

I am not sure which approach to take:

  • 1a. Load all database data into one single model

    1b. Then apply the model to all views, filtering the data inside the view with a proxy model

  • 2a. One model for each view, but filtering done inside sqlite database.

Pros/Cons:

  • Idea 1:

    (+) one model, makes use of model/view advantages (e.g. updating all connected views)

    (-) memory usage could get huge because all data is loaded into a model, but only a subset is shown

  • Idea 2:

    (+) theoeretically lower memory usage because only the filtered data is loaded from the database

    (-) the views can have filters that could lead to intersecting data, meaning the same data would be stored in more than one model -> perhaps practically even bigger memory usage than in Idea 1

The data being loaded here is just case metadata, e.g. title, description, datetime and so on. Bigger data like images, files are not being loaded here. So as the database could indeed grow big (big for this kind of application, say 200 gb for power users), this does not affect the topic of the present question, because the metadata is much, much smaller and is proportional to overall data count, not data size.

Do you have practical experience with such a configuration and can suggest which one to use? It seems to me that Idea 1 is the way to go, but I am not sure about it.

Aucun commentaire:

Enregistrer un commentaire