Skip to content

Commit 6ab8d42

Browse files
Jose García Gimenometa-codesync[bot]
authored andcommitted
Use scoped warm bookmark cache
Summary: Added support in repo_factory to create a scoped bookmarks cache, and use it in the bookmark_service. All other users will still use the other regular trait, that it's always using a predetermined scope (Hg, Git, or AllKinds). Reviewed By: clara-9 Differential Revision: D88157444 fbshipit-source-id: 6587359d4a024e763cd6221e837acd8f7e759ecb
1 parent e8bc91d commit 6ab8d42

File tree

2 files changed

+58
-3
lines changed
  • eden/mononoke
    • repo_attributes/bookmarks/bookmarks_cache/src
    • repo_factory/src

2 files changed

+58
-3
lines changed

eden/mononoke/repo_attributes/bookmarks/bookmarks_cache/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,10 @@ pub trait ScopedBookmarksCache: Send + Sync {
7777
/// Awaits the completion of any ongoing update.
7878
async fn sync(&self, ctx: &CoreContext);
7979
}
80+
81+
/// Combined trait for types that implement both BookmarksCache and ScopedBookmarksCache.
82+
/// This is used internally by RepoFactory to avoid code duplication.
83+
pub trait CombinedBookmarksCache: BookmarksCache + ScopedBookmarksCache {}
84+
85+
/// Auto-implement CombinedBookmarksCache for any type that implements both traits.
86+
impl<T: BookmarksCache + ScopedBookmarksCache> CombinedBookmarksCache for T {}

eden/mononoke/repo_factory/src/lib.rs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ use bookmarks::ArcBookmarks;
6262
use bookmarks::CachedBookmarks;
6363
use bookmarks::bookmark_heads_fetcher;
6464
use bookmarks_cache::ArcBookmarksCache;
65+
use bookmarks_cache::ArcScopedBookmarksCache;
66+
use bookmarks_cache::CombinedBookmarksCache;
6567
use bookmarks_cache::WarmerRequirement;
6668
use bundle_uri::ArcGitBundleUri;
6769
use bundle_uri::SqlGitBundleMetadataStorageBuilder;
@@ -1687,6 +1689,28 @@ impl RepoFactory {
16871689
repo_event_publisher: &ArcRepoEventPublisher,
16881690
phases: &ArcPhases,
16891691
) -> Result<ArcBookmarksCache> {
1692+
let cache = self
1693+
.build_bookmarks_cache_impl(
1694+
bookmarks,
1695+
bookmark_update_log,
1696+
repo_identity,
1697+
repo_derived_data,
1698+
repo_event_publisher,
1699+
phases,
1700+
)
1701+
.await?;
1702+
Ok(cache as ArcBookmarksCache)
1703+
}
1704+
1705+
async fn build_bookmarks_cache_impl(
1706+
&self,
1707+
bookmarks: &ArcBookmarks,
1708+
bookmark_update_log: &ArcBookmarkUpdateLog,
1709+
repo_identity: &ArcRepoIdentity,
1710+
repo_derived_data: &ArcRepoDerivedData,
1711+
repo_event_publisher: &ArcRepoEventPublisher,
1712+
phases: &ArcPhases,
1713+
) -> Result<Arc<dyn CombinedBookmarksCache + Send + Sync>> {
16901714
let warmer_requirement: WarmerRequirement =
16911715
(&self.env.bookmark_cache_options.derived_data).into();
16921716

@@ -1727,7 +1751,8 @@ impl RepoFactory {
17271751
BookmarkCacheDerivedData::NoDerivation => {}
17281752
}
17291753

1730-
Ok(Arc::new(wbc_builder.build().watched().await?))
1754+
Ok(Arc::new(wbc_builder.build().watched().await?)
1755+
as Arc<dyn CombinedBookmarksCache + Send + Sync>)
17311756
}
17321757
#[cfg(fbcode_build)]
17331758
BookmarkCacheKind::Remote(address) => {
@@ -1759,18 +1784,41 @@ impl RepoFactory {
17591784
warmer_requirement,
17601785
);
17611786

1762-
Ok(Arc::new(repo_client))
1787+
Ok(Arc::new(repo_client) as Arc<dyn CombinedBookmarksCache + Send + Sync>)
17631788
}
17641789
#[cfg(not(fbcode_build))]
17651790
BookmarkCacheKind::Remote(_addr) => {
17661791
return Err(anyhow::anyhow!(
17671792
"Remote bookmark cache not supported in non-fbcode builds"
17681793
));
17691794
}
1770-
BookmarkCacheKind::Disabled => Ok(Arc::new(NoopBookmarksCache::new(bookmarks.clone()))),
1795+
BookmarkCacheKind::Disabled => Ok(Arc::new(NoopBookmarksCache::new(bookmarks.clone()))
1796+
as Arc<dyn CombinedBookmarksCache + Send + Sync>),
17711797
}
17721798
}
17731799

1800+
pub async fn scoped_bookmarks_cache(
1801+
&self,
1802+
bookmarks: &ArcBookmarks,
1803+
bookmark_update_log: &ArcBookmarkUpdateLog,
1804+
repo_identity: &ArcRepoIdentity,
1805+
repo_derived_data: &ArcRepoDerivedData,
1806+
repo_event_publisher: &ArcRepoEventPublisher,
1807+
phases: &ArcPhases,
1808+
) -> Result<ArcScopedBookmarksCache> {
1809+
let cache = self
1810+
.build_bookmarks_cache_impl(
1811+
bookmarks,
1812+
bookmark_update_log,
1813+
repo_identity,
1814+
repo_derived_data,
1815+
repo_event_publisher,
1816+
phases,
1817+
)
1818+
.await?;
1819+
Ok(cache as ArcScopedBookmarksCache)
1820+
}
1821+
17741822
pub async fn target_repo_dbs(
17751823
&self,
17761824
bookmarks: &ArcBookmarks,

0 commit comments

Comments
 (0)