@@ -41,14 +41,26 @@ import { RemoteDocumentChangeBuffer } from './remote_document_change_buffer';
41
41
42
42
export type DocumentSizer = ( doc : MaybeDocument ) => number ;
43
43
44
- type DocumentSizeMap = SortedMap < DocumentKey , DocumentSizeEntry > ;
45
- function documentSizeMap ( ) : DocumentSizeMap {
46
- return new SortedMap < DocumentKey , DocumentSizeEntry > ( DocumentKey . comparator ) ;
44
+ /** Miscellaneous collection types / constants. */
45
+ interface MemoryRemoteDocumentCacheEntry extends DocumentSizeEntry {
46
+ readTime : SnapshotVersion ;
47
+ }
48
+
49
+ type DocumentEntryMap = SortedMap < DocumentKey , MemoryRemoteDocumentCacheEntry > ;
50
+ function documentEntryMap ( ) : DocumentEntryMap {
51
+ return new SortedMap < DocumentKey , MemoryRemoteDocumentCacheEntry > (
52
+ DocumentKey . comparator
53
+ ) ;
47
54
}
48
55
49
56
export class MemoryRemoteDocumentCache implements RemoteDocumentCache {
50
- private docs = documentSizeMap ( ) ;
57
+ /** Underlying cache of documents and their read times. */
58
+ private docs = documentEntryMap ( ) ;
59
+
60
+ /** Set of documents changed since last call to `getNewDocumentChanges()`. */
51
61
private newDocumentChanges = documentKeySet ( ) ;
62
+
63
+ /** Size of all cached documents. */
52
64
private size = 0 ;
53
65
54
66
/**
@@ -68,7 +80,8 @@ export class MemoryRemoteDocumentCache implements RemoteDocumentCache {
68
80
*/
69
81
private addEntry (
70
82
transaction : PersistenceTransaction ,
71
- doc : MaybeDocument
83
+ doc : MaybeDocument ,
84
+ readTime : SnapshotVersion
72
85
) : PersistencePromise < void > {
73
86
const key = doc . key ;
74
87
const entry = this . docs . get ( key ) ;
@@ -77,7 +90,8 @@ export class MemoryRemoteDocumentCache implements RemoteDocumentCache {
77
90
78
91
this . docs = this . docs . insert ( key , {
79
92
maybeDocument : doc ,
80
- size : currentSize
93
+ size : currentSize ,
94
+ readTime
81
95
} ) ;
82
96
83
97
this . newDocumentChanges = this . newDocumentChanges . add ( key ) ;
@@ -204,7 +218,9 @@ export class MemoryRemoteDocumentCache implements RemoteDocumentCache {
204
218
const promises : Array < PersistencePromise < void > > = [ ] ;
205
219
this . changes . forEach ( ( key , doc ) => {
206
220
if ( doc ) {
207
- promises . push ( this . documentCache . addEntry ( transaction , doc ) ) ;
221
+ promises . push (
222
+ this . documentCache . addEntry ( transaction , doc , this . readTime )
223
+ ) ;
208
224
} else {
209
225
this . documentCache . removeEntry ( key ) ;
210
226
}
0 commit comments