Skip to content
Open
Show file tree
Hide file tree
Changes from all 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

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

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

3 changes: 3 additions & 0 deletions Cargo.lock

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

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

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

1 change: 1 addition & 0 deletions crates/bin/docs_rs_admin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ docs_rs_logging = { path = "../../lib/docs_rs_logging" }
docs_rs_repository_stats = { path = "../../lib/docs_rs_repository_stats" }
docs_rs_storage = { path = "../../lib/docs_rs_storage" }
docs_rs_types = { path = "../../lib/docs_rs_types" }
docs_rs_uri = { path = "../../lib/docs_rs_uri" }
docs_rs_utils = { path = "../../lib/docs_rs_utils" }
futures-util = { workspace = true }
sqlx = { workspace = true }
Expand Down
69 changes: 66 additions & 3 deletions crates/bin/docs_rs_admin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ use docs_rs_build_queue::priority::{
use docs_rs_context::Context;
use docs_rs_database::{
crate_details,
service_config::{ConfigName, set_config},
service_config::{Abnormality, ConfigName, remove_config, set_config},
};
use docs_rs_fastly::CdnBehaviour as _;
use docs_rs_headers::SurrogateKey;
use docs_rs_repository_stats::workspaces;
use docs_rs_types::{CrateId, KrateName, ReleaseId, Version};
use docs_rs_uri::EscapedURI;
use futures_util::StreamExt;
use rebuilds::queue_rebuilds_faulty_rustdoc;
use std::iter;
Expand All @@ -37,7 +38,7 @@ async fn main() -> Result<()> {
Ok(())
}

#[derive(Debug, Clone, PartialEq, Eq, Parser)]
#[derive(Debug, Clone, PartialEq, Parser)]
#[command(
about = env!("CARGO_PKG_DESCRIPTION"),
version = docs_rs_utils::BUILD_VERSION,
Expand Down Expand Up @@ -350,7 +351,7 @@ impl BuildSubcommand {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
#[derive(Debug, Clone, PartialEq, Subcommand)]
enum DatabaseSubcommand {
/// Run database migration
Migrate {
Expand All @@ -359,6 +360,12 @@ enum DatabaseSubcommand {
version: Option<i64>,
},

/// Manage the abnormality shown in the site header
Abnormality {
#[command(subcommand)]
command: AbnormalitySubcommand,
},

/// temporary command to repackage missing crates into archive storage.
/// starts at the earliest release and works forwards.
Repackage {
Expand Down Expand Up @@ -404,6 +411,8 @@ impl DatabaseSubcommand {
}
.context("Failed to run database migrations")?,

Self::Abnormality { command } => command.handle_args(ctx).await?,

Self::Repackage { limit } => {
let pool = ctx.pool()?;
let storage = ctx.storage()?;
Expand Down Expand Up @@ -504,6 +513,60 @@ impl DatabaseSubcommand {
}
}

#[derive(Debug, Clone, PartialEq, Subcommand)]
enum AbnormalitySubcommand {
/// Set the abnormality shown in the site header
Set {
#[arg(long)]
url: EscapedURI,
#[arg(long)]
text: String,
/// explanation to be shown on the status page, can be HTML
#[arg(long)]
explanation: Option<String>,
},

/// Remove the abnormality shown in the site header
Remove,
}

impl AbnormalitySubcommand {
async fn handle_args(self, ctx: Context) -> Result<()> {
let mut conn = ctx
.pool()?
.get_async()
.await
.context("failed to get a database connection")?;

match self {
Self::Set {
url,
text,
explanation,
} => {
set_config(
&mut conn,
ConfigName::Abnormality,
Abnormality {
url,
text,
explanation,
},
)
.await
.context("failed to set abnormality in database")?;
}
Self::Remove => {
remove_config(&mut conn, ConfigName::Abnormality)
.await
.context("failed to remove abnormality from database")?;
}
}

Ok(())
}
}

#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
enum LimitsSubcommand {
/// Get sandbox limit overrides for a crate
Expand Down

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

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

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

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

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

17 changes: 17 additions & 0 deletions crates/bin/docs_rs_web/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ static SHORT: ResponseCacheHeaders = ResponseCacheHeaders {
is_caching_something: true,
};

/// Cache for a little longer time in the browser & in the CDN.
/// Helps protecting against traffic spikes.
static LONGER: ResponseCacheHeaders = ResponseCacheHeaders {
cache_control: Some(HeaderValue::from_static("public, max-age=600")),
surrogate_control: None,
surrogate_keys: None,
needs_cdn_invalidation: false,
is_caching_something: true,
};

/// don't cache, don't even store. Never. Ever.
static NO_STORE_MUST_REVALIDATE: ResponseCacheHeaders = ResponseCacheHeaders {
cache_control: Some(HeaderValue::from_static(
Expand Down Expand Up @@ -133,6 +143,11 @@ pub enum CachePolicy {
/// Can be used when the content can be a _little_ outdated,
/// while protecting against spikes in traffic.
ShortInCdnAndBrowser,
/// cache for a little longer short time in the browser & CDN.
/// right now: 10 minutes
/// Can be used when the content can be a _little_ outdated,
/// while protecting against spikes in traffic.
LongerInCdnAndBrowser,
/// cache forever in browser & CDN.
/// Valid when you have hashed / versioned filenames and every rebuild would
/// change the filename.
Expand Down Expand Up @@ -160,6 +175,7 @@ impl CachePolicy {
CachePolicy::NoCaching => NO_CACHING.clone(),
CachePolicy::NoStoreMustRevalidate => NO_STORE_MUST_REVALIDATE.clone(),
CachePolicy::ShortInCdnAndBrowser => SHORT.clone(),
CachePolicy::LongerInCdnAndBrowser => LONGER.clone(),
CachePolicy::ForeverInCdnAndBrowser => FOREVER_IN_CDN_AND_BROWSER.clone(),
CachePolicy::ForeverInCdn(surrogate_keys) => {
if config.cache_invalidatable_responses {
Expand Down Expand Up @@ -325,6 +341,7 @@ mod tests {
NoCaching,
NoStoreMustRevalidate,
ShortInCdnAndBrowser,
LongerInCdnAndBrowser,
ForeverInCdnAndBrowser,
ForeverInCdn(key.clone().into()),
ForeverInCdnAndStaleInBrowser(key.clone().into()),
Expand Down
1 change: 1 addition & 0 deletions crates/bin/docs_rs_web/src/handlers/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ mod tests {
let file_path = file?.path();
if file_path.extension() != Some(OsStr::new("html"))
|| file_path.file_stem() == Some(OsStr::new("index"))
|| file_path.file_stem() == Some(OsStr::new("status"))
{
continue;
}
Expand Down
Loading
Loading