PhoneGap Couchbase indexing view


#1

Hi everybody,
I have noticed that the indexing of the views may take several minutes (I have a database with over 12k docs and growing), and, in the meantime, the app (built with Ionic) does not work properly.
This, of course, happens only at the first start-up of the app, but it is annoying.
Is there any way to know when the indexing process is finished? So that the user can be notified when the app is fully functional?
Thanks
Luca


#2

That’s slower than I’d expect (although a PhoneGap app will index more slowly because the map function is JS not native code.) Have you tried optimizing the map function? It’s going to be called 12k+ times, so even a tiny speedup will be noticeable.

The indexing is lazy; it happens the first time the view is queried after documents have been added/changed/removed. If you want to just update the index and know when it’s done, do a very small query (like set limit=1), and when the response arrives you know the index is ready.

A SQLite-based database only allows one thread to access it at a time. So during view indexing, the database isn’t accessible by other threads. ForestDB allows threads to read the database while another thread is updating it.


#3

Thank for your reply.
Is there any “best practice” to write the map function? How I can consider to optimize it and check if the performances will improve?

As for the indexing, there is something strange going on, because, in the meantime the indexing is in progress, for example, I can see a list of documents (so I receive and show a view query), but I cannot get the details of some documents. So if I run some queries I get immediately the response, but I can see that the indexing is not completed because some other parts of the app will not work. So I think that your suggestion would not be applicable in this case, isn’t it?

I would like to try ForestDB, is there any implementation that I can test on PhoneGap/Ionic?

Bye
Luca


#4

Just general optimization — avoid computing the same values more than once, and avoid expensive computations if you can.

What platform of CBLite are you using, on what OS?

I can see a list of documents (so I receive and show a view query), but I cannot get the details of some documents.

Can you describe this in more detail?

I would like to try ForestDB, is there any implementation that I can test on PhoneGap/Ionic?

I don’t think the APIs for enabling ForestDB storage are available from PhoneGap (yet).


#5

I am using the last release on both iOS and Android. More or less the indexing time is the same.

For the views, for example, I have a first page where I list some documents and I get this list from a map view, which gives back only the titles of each document, then, after clicking on each item, I switch to a second view where I show the complete document (retrieved through a new request to the database - getById).
What happens is that I can see the list in the first page, but when I move to the second page I get the document only after indexing is completed.
That’s why it seems strange, because a first request to a view gives a correct response, but a second request to the document does not work.

I will keep looking at ForestDB to check if there is any implementation possible.

Thanks
Luca


#6

What happens is that I can see the list in the first page, but when I move to the second page I get the document only after indexing is completed.

What you’re seeing is that indexing is keeping the database locked, preventing reading the document.

That implies that you’re querying another view at the time. If you can delay querying that view, you’d be able to read the document.


#7

OK. I will try to find out.
As far as you know is the database sending any notification/broadcast message with its status (locked, indexing, etc)?


#8

No, there are no notifications for this. But you are basically in charge of when views index, because you’re the one querying them. If you query a view, the view is done indexing when you get the response.

I looked into locking a bit more, and it actually varies by platform. The .NET implementation, and the Java implementation on recent Android (API 20+), allow reads concurrently with a writer. The Objective-C iOS/Mac implementation doesn’t, although I actually just made a change this morning to allow it to (turns out it was simple) but this missed the deadline for 1.3 so it won’t show up till 1.3.1 at the earliest.


#9

OK. Thank you very much!


#10

I have seen that release couchbase mobile 1.3 is now available. Do you have any release date of the phonegap plugin that includes 1.3?
Thanks
Luca


#11

The Github repo was updated a few days ago for version 1.3.


#12

I must have looked few hours before your update! :slight_smile:
Thanks