private void queueDownloadedRevision ( RevisionInternal rev ) { if ( revisionBodyTransformationBlock != null ) { // Add 'file' properties to attachments pointing to their bodies: for ( Map . Entry < String , Map < String , Object > > entry : ( ( Map < String , Map < String , Object > > ) rev . getProperties ( ) . get ( "_attachments" ) ) . entrySet ( ) ) { String name = entry . getKey ( ) ; Map < String , Object > attachment = entry . getValue ( ) ; attachment . remove ( "file" ) ; if ( attachment . get ( "follows" ) != null && attachment . get ( "data" ) == null ) { String filePath = db . fileForAttachmentDict ( attachment ) . getPath ( ) ; if ( filePath != null ) attachment . put ( "file" , filePath ) ; } } RevisionInternal xformed = transformRevision ( rev ) ; if ( xformed == null ) { Log . v ( TAG , "%s: Transformer rejected revision %s" , this , rev ) ; pendingSequences . removeSequence ( rev . getSequence ( ) ) ; lastSequence = pendingSequences . getCheckpointedValue ( ) ; pauseOrResume ( ) ; return ; } rev = xformed ; // Clean up afterwards Map < String , Map < String , Object > > attachments = ( Map < String , Map < String , Object > > ) rev . getProperties ( ) . get ( "_attachments" ) ; for ( Map . Entry < String , Map < String , Object > > entry : attachments . entrySet ( ) ) { Map < String , Object > attachment = entry . getValue ( ) ; attachment . remove ( "file" ) ; } } // NOTE: should not/not necessary to call Body.compact() // new RevisionInternal(Map<string, Object>) creates Body instance only // with `object`. Serializing object to json causes two unnecessary // JSON serializations. if ( rev . getBody ( ) != null ) queuedMemorySize . addAndGet ( rev . getBody ( ) . getSize ( ) ) ; downloadsToInsert . queueObject ( rev ) ; // if queue memory size is more than maximum, force flush the queue. if ( queuedMemorySize . get ( ) > MAX_QUEUE_MEMORY_SIZE ) { Log . d ( TAG , "Flushing queued memory size at: " + queuedMemorySize ) ; downloadsToInsert . flushAllAndWait ( ) ; } }
This invokes the tranformation block if one is installed and queues the resulting CBL_Revision