protected void pullBulkRevisions ( List < RevisionInternal > bulkRevs ) { int nRevs = bulkRevs . size ( ) ; if ( nRevs == 0 ) { return ; } Log . d ( TAG , "%s bulk-fetching %d remote revisions..." , this , nRevs ) ; Log . d ( TAG , "%s bulk-fetching remote revisions: %s" , this , bulkRevs ) ; if ( ! canBulkGet ) { pullBulkWithAllDocs ( bulkRevs ) ; return ; } Log . v ( TAG , "%s: POST _bulk_get" , this ) ; final List < RevisionInternal > remainingRevs = new ArrayList < RevisionInternal > ( bulkRevs ) ; ++ httpConnectionCount ; final RemoteBulkDownloaderRequest downloader ; try { downloader = new RemoteBulkDownloaderRequest ( clientFactory , remote , true , bulkRevs , db , this . requestHeaders , new RemoteBulkDownloaderRequest . BulkDownloaderDocument ( ) { public void onDocument ( Map < String , Object > props , long size ) { // Got a revision! // Find the matching revision in 'remainingRevs' and get its sequence: RevisionInternal rev ; if ( props . get ( "_id" ) != null ) { rev = new RevisionInternal ( props , size ) ; } else { rev = new RevisionInternal ( ( String ) props . get ( "id" ) , ( String ) props . get ( "rev" ) , false ) ; } int pos = remainingRevs . indexOf ( rev ) ; if ( pos > - 1 ) { rev . setSequence ( remainingRevs . get ( pos ) . getSequence ( ) ) ; remainingRevs . remove ( pos ) ; } else { Log . w ( TAG , "%s : Received unexpected rev rev" , this ) ; } if ( props . get ( "_id" ) != null ) { // Add to batcher ... eventually it will be fed to -insertRevisions:. queueDownloadedRevision ( rev ) ; } else { Status status = statusFromBulkDocsResponseItem ( props ) ; Throwable err = new CouchbaseLiteException ( status ) ; revisionFailed ( rev , err ) ; } } } , new RemoteRequestCompletion ( ) { public void onCompletion ( RemoteRequest remoteRequest , Response httpResponse , Object result , Throwable e ) { // The entire _bulk_get is finished: if ( e != null ) { setError ( e ) ; completedChangesCount . addAndGet ( remainingRevs . size ( ) ) ; } -- httpConnectionCount ; // Start another task if there are still revisions waiting to be pulled: pullRemoteRevisions ( ) ; if ( cancellables != null && cancellables . values ( ) != null && remoteRequest != null ) cancellables . values ( ) . remove ( remoteRequest ) ; } } ) ; } catch ( Exception e ) { Log . e ( TAG , "%s: pullBulkRevisions Exception: %s" , this , e ) ; return ; } downloader . setAuthenticator ( getAuthenticator ( ) ) ; // set compressed request - gzip downloader . setCompressedRequest ( canSendCompressedRequests ( ) ) ; synchronized ( remoteRequestExecutor ) { if ( ! remoteRequestExecutor . isShutdown ( ) ) { Future future = remoteRequestExecutor . submit ( downloader ) ; pendingFutures . add ( future ) ; cancellables . put ( future , downloader ) ; } } }
Get a bunch of revisions in one bulk request . Will use _bulk_get if possible .