@@ -72,7 +72,11 @@ impl ViewsMap {
7272 }
7373 }
7474
75- pub async fn observe_view_change ( & self , uid : i64 , views : HashMap < ViewId , Arc < View > > ) {
75+ /// Observe view changes for a specific user. Requires uid to properly track user-specific changes.
76+ pub async fn observe_view_change ( & self , uid : Option < i64 > , views : HashMap < ViewId , Arc < View > > ) {
77+ let Some ( uid) = uid else {
78+ return ; // Cannot observe changes without uid
79+ } ;
7680 for ( k, v) in views {
7781 self . deletion_cache . insert ( k, v) ;
7882 }
@@ -157,11 +161,12 @@ impl ViewsMap {
157161 }
158162 }
159163
164+ /// Get views belonging to a parent. When uid is provided, includes user-specific enrichment.
160165 pub fn get_views_belong_to < T : ReadTxn > (
161166 & self ,
162167 txn : & T ,
163168 parent_view_id : & ViewId ,
164- uid : i64 ,
169+ uid : Option < i64 > ,
165170 ) -> Vec < Arc < View > > {
166171 match self . get_view_with_txn ( txn, parent_view_id, uid) {
167172 Some ( root_view) => root_view
@@ -205,14 +210,16 @@ impl ViewsMap {
205210 }
206211 }
207212
208- pub fn get_views < T : ReadTxn > ( & self , txn : & T , view_ids : & [ ViewId ] , uid : i64 ) -> Vec < Arc < View > > {
213+ /// Get multiple views by ids. When uid is provided, includes user-specific enrichment.
214+ pub fn get_views < T : ReadTxn > ( & self , txn : & T , view_ids : & [ ViewId ] , uid : Option < i64 > ) -> Vec < Arc < View > > {
209215 view_ids
210216 . iter ( )
211217 . flat_map ( |view_id| self . get_view_with_txn ( txn, view_id, uid) )
212218 . collect :: < Vec < _ > > ( )
213219 }
214220
215- pub fn get_all_views < T : ReadTxn > ( & self , txn : & T , uid : i64 ) -> Vec < Arc < View > > {
221+ /// Get all views. When uid is provided, includes user-specific enrichment like is_favorite.
222+ pub fn get_all_views < T : ReadTxn > ( & self , txn : & T , uid : Option < i64 > ) -> Vec < Arc < View > > {
216223 // since views can be mapped through revisions, we need a map of final_view_id and its predecessors
217224
218225 // first split the keys into ones that have existing mappings (roots) and ones that have not more mapping (leafs)
@@ -252,14 +259,16 @@ impl ViewsMap {
252259 . collect ( )
253260 }
254261
262+ /// Get a view by id. When uid is provided, includes user-specific enrichment like is_favorite.
255263 #[ instrument( level = "trace" , skip_all) ]
256- pub fn get_view < T : ReadTxn > ( & self , txn : & T , view_id : & ViewId , uid : i64 ) -> Option < Arc < View > > {
264+ pub fn get_view < T : ReadTxn > ( & self , txn : & T , view_id : & ViewId , uid : Option < i64 > ) -> Option < Arc < View > > {
257265 self . get_view_with_txn ( txn, view_id, uid)
258266 }
259267
260- /// Return the orphan views.d
268+ /// Return the orphan views.
261269 /// The orphan views are the views that its parent_view_id equal to its view_id.
262- pub fn get_orphan_views_with_txn < T : ReadTxn > ( & self , txn : & T , uid : i64 ) -> Vec < Arc < View > > {
270+ /// When uid is provided, includes user-specific enrichment.
271+ pub fn get_orphan_views_with_txn < T : ReadTxn > ( & self , txn : & T , uid : Option < i64 > ) -> Vec < Arc < View > > {
263272 self
264273 . container
265274 . keys ( txn)
@@ -279,7 +288,7 @@ impl ViewsMap {
279288 & self ,
280289 txn : & T ,
281290 view_id : & ViewId ,
282- uid : i64 ,
291+ uid : Option < i64 > ,
283292 ) -> Option < Arc < View > > {
284293 let ( view_id, mappings) = self . revision_map . mappings ( txn, * view_id) ;
285294 let map_ref = self . container . get_with_txn ( txn, & view_id. to_string ( ) ) ?;
@@ -297,11 +306,12 @@ impl ViewsMap {
297306 /// Gets a view with stronger consistency guarantees, bypassing cache when needed
298307 /// Use this during transactions that might have uncommitted changes
299308 /// Note: Since we removed the cache, this is now identical to get_view_with_txn
309+ /// When uid is provided, includes user-specific enrichment like is_favorite.
300310 pub fn get_view_with_strong_consistency < T : ReadTxn > (
301311 & self ,
302312 txn : & T ,
303313 view_id : & ViewId ,
304- uid : i64 ,
314+ uid : Option < i64 > ,
305315 ) -> Option < Arc < View > > {
306316 self . get_view_with_txn ( txn, view_id, uid)
307317 }
@@ -493,7 +503,7 @@ impl ViewsMap {
493503 new_view_id : & ViewId ,
494504 uid : i64 ,
495505 ) -> bool {
496- if let Some ( old_view) = self . get_view ( txn, old_view_id, uid) {
506+ if let Some ( old_view) = self . get_view ( txn, old_view_id, Some ( uid) ) {
497507 let mut new_view = ( * old_view) . clone ( ) ;
498508 new_view. id = * new_view_id;
499509 new_view. last_edited_by = Some ( uid) ;
@@ -517,7 +527,7 @@ pub(crate) fn view_from_map_ref<T: ReadTxn>(
517527 txn : & T ,
518528 view_relations : & Arc < ParentChildRelations > ,
519529 section_map : & SectionMap ,
520- uid : i64 ,
530+ uid : Option < i64 > ,
521531 mappings : impl IntoIterator < Item = ViewId > ,
522532) -> Option < View > {
523533 let parent_view_id: String = map_ref. get_with_txn ( txn, VIEW_PARENT_ID ) ?;
@@ -556,9 +566,12 @@ pub(crate) fn view_from_map_ref<T: ReadTxn>(
556566 }
557567
558568 let icon = get_icon_from_view_map ( map_ref, txn) ;
559- let is_favorite = section_map
560- . section_op ( txn, Section :: Favorite , uid)
561- . map ( |op| op. contains_with_txn ( txn, & id) )
569+ let is_favorite = uid
570+ . and_then ( |uid| {
571+ section_map
572+ . section_op ( txn, Section :: Favorite , Some ( uid) )
573+ . map ( |op| op. contains_with_txn ( txn, & id) )
574+ } )
562575 . unwrap_or ( false ) ;
563576
564577 let created_by = map_ref. get_with_txn ( txn, VIEW_CREATED_BY ) ;
@@ -821,7 +834,7 @@ impl<'a, 'b, 'c> ViewUpdate<'a, 'b, 'c> {
821834 if let Some ( private_section) =
822835 self
823836 . section_map
824- . section_op ( self . txn , Section :: Private , self . uid . as_i64 ( ) )
837+ . section_op ( self . txn , Section :: Private , Some ( self . uid . as_i64 ( ) ) )
825838 {
826839 if is_private {
827840 private_section. add_sections_item ( self . txn , vec ! [ SectionItem :: new( * self . view_id) ] ) ;
@@ -837,7 +850,7 @@ impl<'a, 'b, 'c> ViewUpdate<'a, 'b, 'c> {
837850 if let Some ( fav_section) =
838851 self
839852 . section_map
840- . section_op ( self . txn , Section :: Favorite , self . uid . as_i64 ( ) )
853+ . section_op ( self . txn , Section :: Favorite , Some ( self . uid . as_i64 ( ) ) )
841854 {
842855 if is_favorite {
843856 fav_section. add_sections_item ( self . txn , vec ! [ SectionItem :: new( * self . view_id) ] ) ;
@@ -861,7 +874,7 @@ impl<'a, 'b, 'c> ViewUpdate<'a, 'b, 'c> {
861874 if let Some ( trash_section) =
862875 self
863876 . section_map
864- . section_op ( self . txn , Section :: Trash , self . uid . as_i64 ( ) )
877+ . section_op ( self . txn , Section :: Trash , Some ( self . uid . as_i64 ( ) ) )
865878 {
866879 if is_trash {
867880 trash_section. add_sections_item ( self . txn , vec ! [ SectionItem :: new( * self . view_id) ] ) ;
@@ -891,7 +904,7 @@ impl<'a, 'b, 'c> ViewUpdate<'a, 'b, 'c> {
891904 self . txn ,
892905 & self . children_map ,
893906 self . section_map ,
894- self . uid . as_i64 ( ) ,
907+ Some ( self . uid . as_i64 ( ) ) ,
895908 [ ] ,
896909 )
897910 }
0 commit comments