@@ -830,16 +830,7 @@ Agent.prototype._broadcastPresence = function(presence, callback) {
830
830
var latestDocVersion = util . dig ( agent . latestDocVersions , presence . c , presence . d ) ;
831
831
var presenceIsUpToDate = presence . v === latestDocVersion ;
832
832
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 ) ;
843
834
}
844
835
845
836
transformer ( agent , presence , function ( error , presence ) {
@@ -866,9 +857,8 @@ Agent.prototype._subscribeDocVersion = function(collection, id, callback) {
866
857
this . backend . subscribe ( this , collection , id , null , function ( error , stream , snapshot ) {
867
858
if ( error ) return callback ( error ) ;
868
859
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 ;
872
862
873
863
agent . _subscribeMapToStream ( agent . latestDocVersionStreams , collection , id , stream , function ( op ) {
874
864
// op.v behind snapshot.v by 1
@@ -882,6 +872,7 @@ Agent.prototype._subscribeDocVersion = function(collection, id, callback) {
882
872
Agent . prototype . _unsubscribeDocVersion = function ( collection , id , callback ) {
883
873
var stream = util . dig ( this . latestDocVersionStreams , collection , id ) ;
884
874
if ( stream ) stream . destroy ( ) ;
875
+ util . digAndRemove ( this . latestDocVersions , collection , id ) ;
885
876
util . nextTick ( callback ) ;
886
877
} ;
887
878
0 commit comments