cleanup pass 2

This commit is contained in:
aecsocket
2026-07-17 12:38:22 +01:00
parent 14ba540203
commit 7a54515f63
5 changed files with 5 additions and 76 deletions
+1 -3
View File
@@ -11,7 +11,7 @@ use crate::models::projects::{
use crate::models::v2::projects::LegacyVersion;
use crate::queue::session::AuthQueue;
use crate::routes::{v2_reroute, v3};
use crate::search::{SearchBackend, SearchState};
use crate::search::SearchState;
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, web};
use serde::{Deserialize, Serialize};
use validator::Validate;
@@ -488,7 +488,6 @@ pub async fn version_delete(
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
search_backend: web::Data<dyn SearchBackend>,
search_state: web::Data<SearchState>,
) -> Result<HttpResponse, ApiError> {
// Returns NoContent, so we don't need to convert the response
@@ -498,7 +497,6 @@ pub async fn version_delete(
pool,
redis,
session_queue,
search_backend,
search_state,
)
.await
+1 -11
View File
@@ -29,8 +29,7 @@ use crate::queue::session::AuthQueue;
use crate::routes::ApiError;
use crate::routes::internal::delphi;
use crate::search::{
SearchBackend, SearchIndexUpdate, SearchQuery, SearchRequest,
SearchResults, SearchState,
SearchBackend, SearchQuery, SearchRequest, SearchResults, SearchState,
};
use crate::util::error::Context;
use crate::util::img;
@@ -2813,15 +2812,6 @@ pub async fn project_delete_internal(
&redis,
)
.await?;
let project_id = project.inner.id.into();
search_state
.backend
.apply_update(SearchIndexUpdate {
removed_projects: std::slice::from_ref(&project_id),
..SearchIndexUpdate::default()
})
.await
.wrap_internal_err("failed to remove project from search index")?;
search_state
.queue
.push_project_removal(project.inner.id.into())
+2 -26
View File
@@ -27,9 +27,7 @@ use crate::models::teams::ProjectPermissions;
use crate::queue::file_scan::get_files_missing_attribution;
use crate::queue::session::AuthQueue;
use crate::routes::internal::delphi;
use crate::search::incremental::consume::reindex_project_versions;
use crate::search::{SearchBackend, SearchState};
use crate::util::error::Context;
use crate::search::SearchState;
use crate::util::img;
use crate::util::validate::validation_errors_to_string;
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, web};
@@ -1136,19 +1134,9 @@ pub async fn version_delete_route(
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
search_backend: web::Data<dyn SearchBackend>,
search_state: web::Data<SearchState>,
) -> Result<HttpResponse, ApiError> {
version_delete(
req,
info,
pool,
redis,
session_queue,
search_backend,
search_state,
)
.await
version_delete(req, info, pool, redis, session_queue, search_state).await
}
pub async fn version_delete(
@@ -1157,7 +1145,6 @@ pub async fn version_delete(
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
search_backend: web::Data<dyn SearchBackend>,
search_state: web::Data<SearchState>,
) -> Result<HttpResponse, ApiError> {
let user = get_user_from_headers(
@@ -1267,17 +1254,6 @@ pub async fn version_delete(
[VersionId::from(version.inner.id)],
)
.await;
let project_id = version.inner.project_id.into();
let version_id = version.inner.id.into();
reindex_project_versions(
&pool,
&redis,
search_backend.as_ref(),
std::slice::from_ref(&project_id),
std::slice::from_ref(&version_id),
)
.await
.wrap_internal_err("failed to update search index after version removal")?;
if result.is_some() {
Ok(HttpResponse::NoContent().body(""))
} else {
@@ -366,30 +366,6 @@ async fn build_changed_project_versions(
Ok(documents)
}
pub async fn reindex_project_versions(
ro_pool: &PgPool,
redis_pool: &RedisPool,
search_backend: &dyn SearchBackend,
project_ids: &[ProjectId],
version_ids: &[VersionId],
) -> eyre::Result<()> {
let documents = build_changed_project_versions(
ro_pool,
redis_pool,
project_ids,
version_ids,
)
.await?;
search_backend
.apply_update(SearchIndexUpdate {
projects: &documents.projects,
versions: &documents.versions,
removed_versions: version_ids,
..SearchIndexUpdate::default()
})
.await
}
#[derive(Debug, Deserialize)]
#[serde(untagged)]
enum SearchProjectIndexQueueEvent {
+1 -12
View File
@@ -213,18 +213,7 @@ async fn index_swaps() {
test_env.api.remove_project("alpha", USER_USER_PAT).await;
assert_status!(&resp, StatusCode::NO_CONTENT);
// We should wait for deletions to be indexed
let projects = test_env
.api
.search_deserialized(
None,
Some(json!([["categories:fabric"]])),
USER_USER_PAT,
)
.await;
assert_eq!(projects.total_hits, 0);
// When we reindex, it should be still gone
// When we reindex, the deleted project should be gone
let resp = test_env.api.reset_search_index().await;
assert_status!(&resp, StatusCode::NO_CONTENT);