@@ -830,16 +830,7 @@ Agent.prototype._broadcastPresence = function(presence, callback) {
830830 var latestDocVersion = util . dig ( agent . latestDocVersions , presence . c , presence . d ) ;
831831 var presenceIsUpToDate = presence . v === latestDocVersion ;
832832 if ( ! presenceIsUpToDate ) {
833- // null presence can't be transformed, so skip the database call and just
834- // set the version to the latest known Doc version
835- if ( presence . p === null ) {
836- transformer = function ( agent , presence , callback ) {
837- presence . v = latestDocVersion ;
838- callback ( null , presence ) ;
839- } ;
840- } else {
841- transformer = backend . transformPresenceToLatestVersion . bind ( backend ) ;
842- }
833+ transformer = backend . transformPresenceToLatestVersion . bind ( backend ) ;
843834 }
844835
845836 transformer ( agent , presence , function ( error , presence ) {
@@ -866,9 +857,8 @@ Agent.prototype._subscribeDocVersion = function(collection, id, callback) {
866857 this . backend . subscribe ( this , collection , id , null , function ( error , stream , snapshot ) {
867858 if ( error ) return callback ( error ) ;
868859
869- util . digOrCreate ( latestDocVersions , collection , id , function ( ) {
870- return snapshot . v ;
871- } ) ;
860+ var versions = latestDocVersions [ collection ] || ( latestDocVersions [ collection ] = Object . create ( null ) ) ;
861+ versions [ id ] = snapshot . v ;
872862
873863 agent . _subscribeMapToStream ( agent . latestDocVersionStreams , collection , id , stream , function ( op ) {
874864 // op.v behind snapshot.v by 1
@@ -882,6 +872,7 @@ Agent.prototype._subscribeDocVersion = function(collection, id, callback) {
882872Agent . prototype . _unsubscribeDocVersion = function ( collection , id , callback ) {
883873 var stream = util . dig ( this . latestDocVersionStreams , collection , id ) ;
884874 if ( stream ) stream . destroy ( ) ;
875+ util . digAndRemove ( this . latestDocVersions , collection , id ) ;
885876 util . nextTick ( callback ) ;
886877} ;
887878
0 commit comments