anvilsign in

collin/anvil · 80bf8535

Trigger language indexing on repository push

Collin Richards · 2026-08-18 01:11 UTC · 80bf8535f5cb3c1225f87f47a863cf228ca2091d · parent 2bc1657f · browse files

modifiedcrates/anvil-core/src/periodic.rs+16 −0
⋯ 146 unchanged lines
147147 }
148148 }
149149
150+/// Trigger language detection for a single repository, updating its LOC percentages.
151+/// This is called immediately after a push to keep metadata current without waiting for
152+/// the periodic job interval. Spawned as a background task so it doesn't block the push response.
153+pub fn trigger_repo_indexing(app: App, repo_id: i64, repo_path: std::path::PathBuf) {
154+ tokio::spawn(async move {
155+ let repo_git_path = repo_path.join(".git");
156+ if repo_git_path.exists()
157+ && let Ok(detection) = language::detect(&repo_git_path).await
158+ && let Err(e) =
159+ repos::update_languages(&app.db, repo_id, &detection.primary, &detection.json).await
160+ {
161+ tracing::warn!(repo_id = repo_id, error = %e, "failed to update languages after push");
162+ }
163+ });
164+}
165+
150166 /// Try to extract the first image URL from a repository's README file.
151167 /// Scans the repository for a README file, reads it, and returns the first image URL found.
152168 async fn extract_readme_image(repo_path: &Path) -> Option<String> {
⋯ 21 unchanged lines
modifiedcrates/anvil-web/src/git_http.rs+2 −0
⋯ 16 unchanged lines
1717 App,
1818 Repository,
1919 access,
20+ periodic,
2021 repos,
2122 users,
2223 };
⋯ 257 unchanged lines
280281 if !meta.mirror_url.is_empty() {
281282 anvil_git::mirror::spawn_push(path.clone(), meta.mirror_url.clone());
282283 }
284+ periodic::trigger_repo_indexing(app.clone(), meta.id, path);
283285 rpc_response(Service::ReceivePack.result_content_type(), Body::from(b))
284286 }
285287 Err(e) => internal(e),
⋯ 2 unchanged lines