Best practice to create views in Couch Base lite Android

Hi Team,

What is the best practice to create view in couchbase lite android.

Should all the views be created before starting the replication so that when the data starts syncing and simultaneously data is pushed in the views.

Because I have seen a case where the data is synced first (39000 documents) and then view creation is called and it takes lot of time for the first time to populate the view. Can it be avoided by creating view first and then start replication.

This happens only when the app runs for the first time.

you can create view after create bucket for the first time, I think it is the better.

  1. Does it mean load data first and then create the view. But that I have found very slow.
  2. So should we create the database then create view and then start replication. At least sounds faster

which one @atom_yang please suggest.

I think option 2 is better.

Theoretically, a total time of indexing should be faster with indexing at once after downloaded all data.

We have around 45000 documents. Which are of 31 types. What should be a number of views for best performance.

Views are indexed lazily. When you query a view, any documents that have been created or updated since the last query will be indexed before the query itself runs. But simply updating/adding/deleting a document does not do anything to views.

So basically it doesn’t matter whether you create the views before or after the replication. It’s when you query them that matters.

It’s probably slightly more efficient to do all the indexing at once after the replication completes. But this does lead to a lot of lag or blocking in the UI. Probably the best approach is to call View.updateIndex periodically if you know that a lot of documents are being pulled. On Java or C# you can call it on a background thread, or on iOS there’s an asynchronous version of the method.

That’s too general a question; it depends on your use case. Zero views would give you the best performance, of course :wink: The real question is what kinds of queries you need to make; from that you can work out the views. It’s very much like looking at your SELECT statements in a SQL database app and working out what indexes to create to make them fast.