Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix archive index caching for source archives, don't ignore source fetch errors #2323

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,14 @@ impl AsyncStorage {
&self,
name: &str,
version: &str,
latest_build_id: i32,
path: &str,
archive_storage: bool,
) -> Result<Blob> {
Ok(if archive_storage {
self.get_from_archive(
&source_archive_path(name, version),
0, // we assume the source archive can't ever change for a release
latest_build_id,
path,
self.max_file_size_for(path),
None,
Expand Down Expand Up @@ -633,13 +634,17 @@ impl Storage {
&self,
name: &str,
version: &str,
latest_build_id: i32,
path: &str,
archive_storage: bool,
) -> Result<Blob> {
self.runtime.block_on(
self.inner
.fetch_source_file(name, version, path, archive_storage),
)
self.runtime.block_on(self.inner.fetch_source_file(
name,
version,
latest_build_id,
path,
archive_storage,
))
}

pub(crate) fn rustdoc_file_exists(
Expand Down
9 changes: 8 additions & 1 deletion src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ impl CrateDetails {
.fetch_source_file(
&self.name,
&self.version,
self.latest_build_id.unwrap_or(0),
"Cargo.toml",
self.archive_storage,
)
Expand All @@ -282,7 +283,13 @@ impl CrateDetails {
};
for path in &paths {
match storage
.fetch_source_file(&self.name, &self.version, path, self.archive_storage)
.fetch_source_file(
&self.name,
&self.version,
self.latest_build_id.unwrap_or(0),
path,
self.archive_storage,
)
.await
{
Ok(readme) => {
Expand Down
39 changes: 33 additions & 6 deletions src/web/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ use super::{error::AxumResult, match_version_axum};
use crate::{
db::Pool,
impl_axum_webpage,
storage::PathNotFoundError,
utils::get_correct_docsrs_style_file,
web::{
cache::CachePolicy, error::AxumNope, file::File as DbFile, headers::CanonicalUrl,
MatchSemver, MetaData,
},
AsyncStorage,
};
use anyhow::Result;
use anyhow::{Context as _, Result};
use axum::{extract::Path, headers::HeaderMapExt, response::IntoResponse, Extension};
use serde::{Deserialize, Serialize};
use std::{cmp::Ordering, sync::Arc};
Expand Down Expand Up @@ -225,8 +226,18 @@ pub(crate) async fn source_browser_handler(
}
};

let archive_storage = sqlx::query_scalar!(
"SELECT archive_storage
let row = sqlx::query!(
"SELECT
releases.archive_storage,
(
SELECT id
FROM builds
WHERE
builds.rid = releases.id AND
builds.build_status = TRUE
ORDER BY build_time DESC
LIMIT 1
) AS latest_build_id
FROM releases
INNER JOIN crates ON releases.crate_id = crates.id
WHERE
Expand All @@ -241,10 +252,26 @@ pub(crate) async fn source_browser_handler(
// try to get actual file first
// skip if request is a directory
let blob = if !path.ends_with('/') {
storage
.fetch_source_file(&name, &version, &path, archive_storage)
match storage
.fetch_source_file(
&name,
&version,
row.latest_build_id.unwrap_or(0),
&path,
row.archive_storage,
)
.await
.ok()
.context("error fetching source file")
{
Ok(blob) => Some(blob),
Err(err) => {
if err.downcast_ref::<PathNotFoundError>().is_some() {
syphar marked this conversation as resolved.
Show resolved Hide resolved
None
} else {
return Err(err.into());
}
}
}
} else {
None
};
Expand Down