perf(registry): use rwlock over mutex for repository data

This commit is contained in:
daimond113 2025-01-09 22:40:41 +01:00
parent 217ca238ff
commit 685700f572
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C
8 changed files with 14 additions and 9 deletions

View file

@ -8,17 +8,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added ### Added
- Support deprecating and yanking packages by @daimond113 - Support deprecating and yanking packages by @daimond113
- Add yanking & deprecating to registry by @daimond113
- Log more information about configured auth & storage by @daimond113
### Changed ### Changed
- Asyncify blocking operations by @daimond113 - Asyncify blocking operations by @daimond113
### Performance
- Switch to using a `RwLock` over a `Mutex` to store repository data by @daimond113
## [0.1.2] ## [0.1.2]
### Changed ### Changed
- Update to pesde lib API changes by @daimond113 - Update to pesde lib API changes by @daimond113
## [0.1.1] - 2024-12-19 ## [0.1.1] - 2024-12-19
### Changed ### Changed
- Switch to traccing for logging by @daimond113 - Switch to tracing for logging by @daimond113
## [0.1.0] - 2024-12-14 ## [0.1.0] - 2024-12-14
### Added ### Added

View file

@ -36,7 +36,7 @@ pub async fn deprecate_package_version(
String::new() String::new()
}; };
let name = path.into_inner(); let name = path.into_inner();
let source = app_state.source.lock().await; let source = app_state.source.write().await;
let Some(scope_info) = read_scope_info(&app_state, name.scope(), &source).await? else { let Some(scope_info) = read_scope_info(&app_state, name.scope(), &source).await? else {
return Ok(HttpResponse::NotFound().finish()); return Ok(HttpResponse::NotFound().finish());

View file

@ -23,7 +23,7 @@ pub async fn get_package_version(
) -> Result<HttpResponse, RegistryError> { ) -> Result<HttpResponse, RegistryError> {
let (name, version, target) = path.into_inner(); let (name, version, target) = path.into_inner();
let Some(file) = read_package(&app_state, &name, &*app_state.source.lock().await).await? else { let Some(file) = read_package(&app_state, &name, &*app_state.source.read().await).await? else {
return Ok(HttpResponse::NotFound().finish()); return Ok(HttpResponse::NotFound().finish());
}; };

View file

@ -13,7 +13,7 @@ pub async fn get_package_versions(
) -> Result<impl Responder, RegistryError> { ) -> Result<impl Responder, RegistryError> {
let name = path.into_inner(); let name = path.into_inner();
let Some(file) = read_package(&app_state, &name, &*app_state.source.lock().await).await? else { let Some(file) = read_package(&app_state, &name, &*app_state.source.read().await).await? else {
return Ok(HttpResponse::NotFound().finish()); return Ok(HttpResponse::NotFound().finish());
}; };

View file

@ -52,7 +52,7 @@ pub async fn publish_package(
bytes: Bytes, bytes: Bytes,
user_id: web::ReqData<UserId>, user_id: web::ReqData<UserId>,
) -> Result<HttpResponse, RegistryError> { ) -> Result<HttpResponse, RegistryError> {
let source = app_state.source.lock().await; let source = app_state.source.write().await;
source source
.refresh(&RefreshOptions { .refresh(&RefreshOptions {
project: app_state.project.clone(), project: app_state.project.clone(),

View file

@ -52,7 +52,7 @@ pub async fn search_packages(
) )
.unwrap(); .unwrap();
let source = app_state.source.lock().await; let source = app_state.source.read().await;
let repo = gix::open(source.path(&app_state.project))?; let repo = gix::open(source.path(&app_state.project))?;
let tree = root_tree(&repo)?; let tree = root_tree(&repo)?;

View file

@ -20,7 +20,7 @@ pub async fn yank_package_version(
) -> Result<HttpResponse, RegistryError> { ) -> Result<HttpResponse, RegistryError> {
let yanked = request.method() != Method::DELETE; let yanked = request.method() != Method::DELETE;
let (name, version, target) = path.into_inner(); let (name, version, target) = path.into_inner();
let source = app_state.source.lock().await; let source = app_state.source.write().await;
let Some(scope_info) = read_scope_info(&app_state, name.scope(), &source).await? else { let Some(scope_info) = read_scope_info(&app_state, name.scope(), &source).await? else {
return Ok(HttpResponse::NotFound().finish()); return Ok(HttpResponse::NotFound().finish());

View file

@ -47,7 +47,7 @@ pub fn make_reqwest() -> reqwest::Client {
} }
pub struct AppState { pub struct AppState {
pub source: tokio::sync::Mutex<PesdePackageSource>, pub source: tokio::sync::RwLock<PesdePackageSource>,
pub project: Project, pub project: Project,
pub storage: Storage, pub storage: Storage,
pub auth: Auth, pub auth: Auth,
@ -134,7 +134,7 @@ async fn run() -> std::io::Result<()> {
tracing::info!("auth: {auth}"); tracing::info!("auth: {auth}");
auth auth
}, },
source: tokio::sync::Mutex::new(source), source: tokio::sync::RwLock::new(source),
project, project,
search_reader, search_reader,