@@ -341,7 +341,7 @@ where
341
341
. unwrap_or ( ( Durability :: MAX , Revision :: max ( ) ) ) ;
342
342
343
343
let value = value. shared . get_mut ( ) . with ( |value_shared| {
344
- // SAFETY: We hold the lock and the value has not been read in this revision .
344
+ // SAFETY: We hold the lock.
345
345
let value_shared = unsafe { & mut * value_shared } ;
346
346
347
347
// Mark the slot as reused.
@@ -354,13 +354,31 @@ where
354
354
unsafe { & * UnsafeRef :: into_raw ( cursor. remove ( ) . unwrap ( ) ) }
355
355
} ) ;
356
356
357
- // SAFETY: We hold the lock.
358
- let id = value. shared . with_mut ( |value_shared| unsafe {
357
+ let id = value. shared . with_mut ( |value_shared| {
358
+ // SAFETY: We hold the lock.
359
+ let value_shared = unsafe { & mut * value_shared } ;
360
+
359
361
// Note we need to retain the previous durability here to ensure queries trying
360
362
// to read the old value are revalidated.
361
- ( * value_shared) . durability =
362
- std:: cmp:: max ( ( * value_shared) . durability , durability) ;
363
- ( * value_shared) . id
363
+ value_shared. durability = std:: cmp:: max ( value_shared. durability , durability) ;
364
+
365
+ let index = self . database_key_index ( value_shared. id ) ;
366
+
367
+ // Record a dependency on the value.
368
+ zalsa_local. report_tracked_read_simple (
369
+ index,
370
+ value_shared. durability ,
371
+ value_shared. first_interned_at ,
372
+ ) ;
373
+
374
+ zalsa. event ( & || {
375
+ Event :: new ( EventKind :: DidReuseInternedValue {
376
+ key : index,
377
+ revision : current_revision,
378
+ } )
379
+ } ) ;
380
+
381
+ value_shared. id
364
382
} ) ;
365
383
366
384
// Reuse the value slot with the new data.
@@ -371,20 +389,15 @@ where
371
389
* fields = self . to_internal_data ( assemble ( id, key) ) ;
372
390
} ) ;
373
391
392
+ // TODO: Need to free the memory safely here.
393
+ value. memos . clear ( ) ;
394
+
374
395
// Move the value to the front of the LRU list.
375
396
//
376
397
// SAFETY: The value pointer is valid for the lifetime of the database
377
398
// and only accessed mutably while holding the lock.
378
399
shared. lru . push_front ( unsafe { UnsafeRef :: from_raw ( value) } ) ;
379
400
380
- let index = self . database_key_index ( id) ;
381
- zalsa. event ( & || {
382
- Event :: new ( EventKind :: DidReuseInternedValue {
383
- key : index,
384
- revision : current_revision,
385
- } )
386
- } ) ;
387
-
388
401
return id;
389
402
}
390
403
}
0 commit comments