couchbaselabs / TouchDB-Android

CouchDB-compatible mobile database; Android version

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

remove TDDatabase.getAllViews() API

dwt opened this issue · comments

I found this because I was replicating a database to the device (with js views in the design document) and wanted to iterate all views to index them.

And was a bit surprised as they didn't come up if the haven't been queried before.

Looking at the implementation this seems logical as it just takes the list of views that it has data for in the db - which is always missing new ones.

I'm not sure this will get fixed. In fact I'd probably be more in favor of removing the method entirely. CouchDB doesn't offer any such way of listing all the views, so I'm not really sure why we do.

TouchDB doesn't know anything about the javascript views, so we'd have to add some code in the -javascript module to find design documents, parse them for views functions, then register them.

I'll leave the issue open for now and think about this some more.

I'm not sure this will get fixed. In fact I'd probably be more in favor of removing the method entirely. CouchDB doesn't offer any such way of listing all the views, so I'm not really sure why we do.

Whatever the direction you go, I'd be very happy if at least some way to do this still works, as it's a requirement for me to be able to iterate views and trigger indexing of them - or I'd not be able to use TouchDB right now.

Here's what I do right now and what works. As far as I understand ektorp is using only couchdb public api to achieve this:

    private void indexAllViewsInDesignDocumentNamed(String dbName, String designDocumentName) {
        Log.i(TAG, "indexAllViewsInDesignDocumentNamed(" + dbName + ", " + designDocumentName + ")");

        HttpClient httpClient = new TouchDBHttpClient(server);
        CouchDbInstance instance = new StdCouchDbInstance(httpClient);
        CouchDbConnector connector = instance.createConnector(dbName, true);
        DesignDocument document = connector.get(DesignDocument.class, "_design/" + designDocumentName);
        Map<String, View> views = document.getViews();
        long startTime = System.currentTimeMillis(); 
        for (String viewName : views.keySet()) {
            Log.i(TAG, "Found view: " + viewName);
            ViewQuery query = new ViewQuery()
                .designDocId("_design/" + designDocumentName)
                .viewName(viewName)
                .key("non existant key to block json un-/ serialization"); 
            connector.queryView(query); 
        }
        long stopTime = System.currentTimeMillis();
        long duration = stopTime - startTime;
        Log.i(TAG, "indexing took " + (duration) + " milliseconds or " + (duration / 1000) + " seconds");
    }

I think the approach you show here is fine. Is there any reason you'd rather use getAllViews()?

Am 13.07.2012 um 02:18 schrieb Marty Schoch:

I think the approach you show here is fine. Is there any reason you'd rather use getAllViews()?

TDView has an update index method that guarantees that only the index is updated - I haven't found a similar API on Ektorp.

The current workaround with the non existing key should be ok - but I'd prefer not to need that workaround.

Regards,
Martin

we should remove this API