couchbaselabs / TouchDB-Android

CouchDB-compatible mobile database; Android version

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

viewquery is empty first time

anna-b opened this issue · comments

When I query the view for the first time, it returns nothing. But if I query for the second time - everything is fine.
There is a difference in the LogCat info:

-- first time --

08-09 11:07:45.717: V/TDDatabase(18423): Re-indexing view findUserInfo/findByType ...
08-09 11:07:45.717: V/TDDatabase(18423): Query findMeetingAssets/findByType: SELECT key, value, docid FROM maps, revs, docs WHERE maps.view_id=? AND revs.sequence = maps.sequence AND docs.doc_id = revs.doc_id ORDER BY key LIMIT ? OFFSET ?

-- second time --

08-09 11:07:45.727: V/TDDatabase(18423): Re-indexing view findUserInfo/findByType ...
08-09 11:07:45.727: V/TDDatabase(18423): call map for sequence=1
08-09 11:07:45.727: V/TDDatabase(18423): call map for sequence=61
08-09 11:07:45.727: V/TDDatabase(18423): ...Finished re-indexing view findUserInfo/findByType up to sequence 61 (deleted 0 added ?)

this "call map for sequence" seems to make things work, how can I make it so that I receive the data with the first request?

Here is the view:
createViewUser(Consts.DOCUMENT_TYPE_USERINFO, requestNumber, Consts.FIND_DOCUMENT_USERINFO);

private void createViewUser(final String typeName, String mapRequestNumber, final String docName) {

TDView view = localDbUser.getViewNamed(String.format("%s/%s", docName, Consts.FIND_BY_TYPE));

view.setMapReduceBlocks(new TDViewMapBlock() {

@OverRide

public void map(Map<String, Object> document, TDViewMapEmitBlock emitter) {

String type = (String) document.get("type");

if (typeName.equals(type)) {

emitter.emit(null, document);

}

}

}, null, mapRequestNumber);

}

Here is the view query:
ViewQuery query = new ViewQuery().designDocId(Consts.D_DOC_ID + Consts.FIND_DOCUMENT_USERMEETING).viewName(Consts.FIND_BY_TYPE);

ViewResult viewResult = mCouchDbConnectorUser.queryView(query);

List listRowsMeetings = viewResult.getRows();