Skip to content

Commit 661a7a5

Browse files
committed
remove temporary archive index fixing command
1 parent a9f2572 commit 661a7a5

6 files changed

+9
-185
lines changed

.sqlx/query-27e9c3c8c3f7770a31967760fdce2ff0304cd9f28c3c8bc056c5b2a20952fc99.json

Lines changed: 0 additions & 46 deletions
This file was deleted.

.sqlx/query-72a4b5a8e046a7196d7f27baad5ed82e22ad7b5333749fae4c75e0b8e1066e7f.json

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/bin/cratesfyi.rs

Lines changed: 3 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1+
use std::env;
12
use std::fmt::Write;
23
use std::net::SocketAddr;
34
use std::path::PathBuf;
45
use std::str::FromStr;
56
use std::sync::Arc;
6-
use std::{env, fs};
77

88
use anyhow::{anyhow, Context as _, Error, Result};
99
use axum::async_trait;
1010
use clap::{Parser, Subcommand, ValueEnum};
1111
use docs_rs::cdn::CdnBackend;
1212
use docs_rs::db::{self, add_path_into_database, Overrides, Pool, PoolClient};
1313
use docs_rs::repositories::RepositoryStatsUpdater;
14-
use docs_rs::storage::{rustdoc_archive_path, source_archive_path, PathNotFoundError};
1514
use docs_rs::utils::{
1615
get_config, get_crate_pattern_and_priority, list_crate_priorities, queue_builder,
17-
remove_crate_priority, set_config, set_crate_priority, spawn_blocking, ConfigName,
16+
remove_crate_priority, set_config, set_crate_priority, ConfigName,
1817
};
1918
use docs_rs::{
2019
start_background_metrics_webserver, start_web_server, AsyncStorage, BuildQueue, Config,
@@ -24,7 +23,6 @@ use docs_rs::{
2423
use futures_util::StreamExt;
2524
use humantime::Duration;
2625
use once_cell::sync::OnceCell;
27-
use rusqlite::{Connection, OpenFlags};
2826
use sentry::TransactionContext;
2927
use tokio::runtime::{Builder, Runtime};
3028
use tracing_log::LogTracer;
@@ -511,9 +509,6 @@ enum DatabaseSubcommand {
511509
/// temporary commant to update the `crates.latest_version_id` field
512510
UpdateLatestVersionId,
513511

514-
/// temporary command to rebuild a subset of the archive indexes
515-
FixBrokenArchiveIndexes,
516-
517512
/// Updates Github/Gitlab stats for crates.
518513
UpdateRepositoryFields,
519514

@@ -572,99 +567,6 @@ impl DatabaseSubcommand {
572567
.context("Failed to run database migrations")?
573568
}
574569

575-
Self::FixBrokenArchiveIndexes => {
576-
let pool = ctx.pool()?;
577-
let build_queue = ctx.build_queue()?;
578-
ctx.runtime()?
579-
.block_on(async {
580-
async fn queue_rebuild(
581-
build_queue: Arc<BuildQueue>,
582-
name: &str,
583-
version: &str,
584-
) -> Result<()> {
585-
spawn_blocking({
586-
let name = name.to_owned();
587-
let version = version.to_owned();
588-
move || {
589-
if !build_queue.has_build_queued(&name, &version)? {
590-
build_queue.add_crate(&name, &version, 5, None)?;
591-
}
592-
Ok(())
593-
}
594-
})
595-
.await
596-
}
597-
let storage = ctx.async_storage().await?;
598-
let mut conn = pool.get_async().await?;
599-
let mut result_stream = sqlx::query!(
600-
"
601-
SELECT c.name, r.version, r.release_time
602-
FROM crates c, releases r
603-
WHERE c.id = r.crate_id AND r.release_time IS NOT NULL
604-
ORDER BY r.release_time DESC
605-
"
606-
)
607-
.fetch(&mut *conn);
608-
609-
while let Some(row) = result_stream.next().await {
610-
let row = row?;
611-
612-
println!(
613-
"checking index for {} {} ({:?})",
614-
row.name, row.version, row.release_time
615-
);
616-
617-
for path in &[
618-
rustdoc_archive_path(&row.name, &row.version),
619-
source_archive_path(&row.name, &row.version),
620-
] {
621-
let local_archive_index_filename = match storage
622-
.download_archive_index(path, 42)
623-
.await
624-
{
625-
Ok(path) => path,
626-
Err(err)
627-
if err.downcast_ref::<PathNotFoundError>().is_some() =>
628-
{
629-
continue
630-
}
631-
Err(err) => return Err(err),
632-
};
633-
634-
let count = {
635-
let connection = match Connection::open_with_flags(
636-
&local_archive_index_filename,
637-
OpenFlags::SQLITE_OPEN_READ_ONLY
638-
| OpenFlags::SQLITE_OPEN_NO_MUTEX,
639-
) {
640-
Ok(conn) => conn,
641-
Err(err) => {
642-
println!("... error opening sqlite db, queueing rebuild: {:?}", err);
643-
queue_rebuild(build_queue.clone(), &row.name, &row.version).await?;
644-
continue;
645-
}
646-
};
647-
let mut stmt =
648-
connection.prepare("SELECT count(*) FROM files")?;
649-
650-
stmt.query_row([], |row| Ok(row.get::<_, usize>(0)))??
651-
};
652-
653-
fs::remove_file(&local_archive_index_filename)?;
654-
655-
if count >= 65000 {
656-
println!("...big index, queueing rebuild");
657-
queue_rebuild(build_queue.clone(), &row.name, &row.version)
658-
.await?;
659-
}
660-
}
661-
}
662-
663-
Ok::<(), anyhow::Error>(())
664-
})
665-
.context("Failed to queue rebuilds for big documentation sizes")?
666-
}
667-
668570
Self::UpdateLatestVersionId => {
669571
let pool = ctx.pool()?;
670572
ctx.runtime()?
@@ -679,7 +581,7 @@ impl DatabaseSubcommand {
679581
while let Some(row) = result_stream.next().await {
680582
let row = row?;
681583

682-
println!("handling crate {} ", row.name);
584+
println!("handling crate {}", row.name);
683585

684586
db::update_latest_version_id(&mut update_conn, row.id).await?;
685587
}

src/build_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl BuildQueue {
151151
.collect())
152152
}
153153

154-
pub fn has_build_queued(&self, name: &str, version: &str) -> Result<bool> {
154+
pub(crate) fn has_build_queued(&self, name: &str, version: &str) -> Result<bool> {
155155
Ok(self
156156
.db
157157
.get()?

src/storage/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type FileRange = RangeInclusive<u64>;
2828

2929
#[derive(Debug, thiserror::Error)]
3030
#[error("path not found")]
31-
pub struct PathNotFoundError;
31+
pub(crate) struct PathNotFoundError;
3232

3333
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
3434
pub(crate) struct Blob {
@@ -304,7 +304,7 @@ impl AsyncStorage {
304304
}
305305

306306
#[instrument]
307-
pub async fn download_archive_index(
307+
pub(super) async fn download_archive_index(
308308
&self,
309309
archive_path: &str,
310310
latest_build_id: i32,
@@ -823,11 +823,11 @@ fn detect_mime(file_path: impl AsRef<Path>) -> &'static str {
823823
}
824824
}
825825

826-
pub fn rustdoc_archive_path(name: &str, version: &str) -> String {
826+
pub(crate) fn rustdoc_archive_path(name: &str, version: &str) -> String {
827827
format!("rustdoc/{name}/{version}.zip")
828828
}
829829

830-
pub fn source_archive_path(name: &str, version: &str) -> String {
830+
pub(crate) fn source_archive_path(name: &str, version: &str) -> String {
831831
format!("sources/{name}/{version}.zip")
832832
}
833833

src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ where
110110
/// })
111111
/// .await?
112112
/// ```
113-
pub async fn spawn_blocking<F, R>(f: F) -> Result<R>
113+
pub(crate) async fn spawn_blocking<F, R>(f: F) -> Result<R>
114114
where
115115
F: FnOnce() -> Result<R> + Send + 'static,
116116
R: Send + 'static,

0 commit comments

Comments
 (0)