Skip to content

Commit b879020

Browse files
committed
remove archive index sqlite connection pool for simplicity
1 parent 3f50d6b commit b879020

File tree

6 files changed

+14
-152
lines changed

6 files changed

+14
-152
lines changed

Cargo.lock

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ semver = { version = "1.0.4", features = ["serde"] }
4040
slug = "0.1.1"
4141
r2d2 = "0.8"
4242
r2d2_postgres = "0.18"
43-
r2d2_sqlite = "0.22.0"
4443
sqlx = { version = "0.7", features = [ "runtime-tokio", "postgres", "chrono" ] }
4544
url = { version = "2.1.1", features = ["serde"] }
4645
docsrs-metadata = { path = "crates/metadata" }

src/config.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ pub struct Config {
1515
pub(crate) max_pool_size: u32,
1616
pub(crate) min_pool_idle: u32,
1717

18-
// local pool for sqlite connections
19-
pub(crate) max_sqlite_pool_size: u64,
20-
2118
// Storage params
2219
pub(crate) storage_backend: StorageKind,
2320

@@ -143,7 +140,6 @@ impl Config {
143140

144141
database_url: require_env("DOCSRS_DATABASE_URL")?,
145142
max_pool_size: env("DOCSRS_MAX_POOL_SIZE", 90)?,
146-
max_sqlite_pool_size: env("DOCSRS_MAX_SQLITE_POOL_SIZE", 500)?,
147143
min_pool_idle: env("DOCSRS_MIN_POOL_IDLE", 10)?,
148144

149145
storage_backend: env("DOCSRS_STORAGE_BACKEND", StorageKind::Database)?,

src/storage/archive_index.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use crate::error::Result;
22
use crate::storage::{compression::CompressionAlgorithm, FileRange};
33
use anyhow::{bail, Context as _};
4-
use rusqlite::{Connection, OptionalExtension};
4+
use rusqlite::{Connection, OpenFlags, OptionalExtension};
55
use std::{fs, io, path::Path};
66

7-
use super::sqlite_pool::SqliteConnectionPool;
8-
97
#[derive(PartialEq, Eq, Debug)]
108
pub(crate) struct FileInfo {
119
range: FileRange,
@@ -77,8 +75,8 @@ pub(crate) fn create<R: io::Read + io::Seek, P: AsRef<Path>>(
7775
fn find_in_sqlite_index(conn: &Connection, search_for: &str) -> Result<Option<FileInfo>> {
7876
let mut stmt = conn.prepare(
7977
"
80-
SELECT start, end, compression
81-
FROM files
78+
SELECT start, end, compression
79+
FROM files
8280
WHERE path = ?
8381
",
8482
)?;
@@ -104,11 +102,12 @@ fn find_in_sqlite_index(conn: &Connection, search_for: &str) -> Result<Option<Fi
104102
pub(crate) fn find_in_file<P: AsRef<Path>>(
105103
archive_index_path: P,
106104
search_for: &str,
107-
pool: &SqliteConnectionPool,
108105
) -> Result<Option<FileInfo>> {
109-
pool.with_connection(archive_index_path, |connection| {
110-
find_in_sqlite_index(connection, search_for)
111-
})
106+
let connection = Connection::open_with_flags(
107+
archive_index_path,
108+
OpenFlags::SQLITE_OPEN_READ_ONLY | OpenFlags::SQLITE_OPEN_NO_MUTEX,
109+
)?;
110+
find_in_sqlite_index(&connection, search_for)
112111
}
113112

114113
#[cfg(test)]
@@ -141,19 +140,13 @@ mod tests {
141140
let tempfile = tempfile::NamedTempFile::new().unwrap().into_temp_path();
142141
create(&mut tf, &tempfile).unwrap();
143142

144-
let fi = find_in_file(&tempfile, "testfile1", &SqliteConnectionPool::default())
145-
.unwrap()
146-
.unwrap();
143+
let fi = find_in_file(&tempfile, "testfile1").unwrap().unwrap();
147144

148145
assert_eq!(fi.range, FileRange::new(39, 459));
149146
assert_eq!(fi.compression, CompressionAlgorithm::Bzip2);
150147

151-
assert!(find_in_file(
152-
&tempfile,
153-
"some_other_file",
154-
&SqliteConnectionPool::default(),
155-
)
156-
.unwrap()
157-
.is_none());
148+
assert!(find_in_file(&tempfile, "some_other_file",)
149+
.unwrap()
150+
.is_none());
158151
}
159152
}

src/storage/mod.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ mod archive_index;
22
mod compression;
33
mod database;
44
mod s3;
5-
mod sqlite_pool;
65

76
pub use self::compression::{compress, decompress, CompressionAlgorithm, CompressionAlgorithms};
87
use self::database::DatabaseBackend;
98
use self::s3::S3Backend;
10-
use self::sqlite_pool::SqliteConnectionPool;
119
use crate::error::Result;
1210
use crate::web::metrics::RenderingTimesRecorder;
1311
use crate::{db::Pool, utils::spawn_blocking, Config, InstanceMetrics};
@@ -16,7 +14,6 @@ use chrono::{DateTime, Utc};
1614
use fn_error_context::context;
1715
use path_slash::PathExt;
1816
use std::io::BufReader;
19-
use std::num::NonZeroU64;
2017
use std::{
2118
collections::{HashMap, HashSet},
2219
ffi::OsStr,
@@ -114,7 +111,6 @@ enum StorageBackend {
114111
pub struct AsyncStorage {
115112
backend: StorageBackend,
116113
config: Arc<Config>,
117-
sqlite_pool: Arc<SqliteConnectionPool>,
118114
}
119115

120116
impl AsyncStorage {
@@ -124,10 +120,6 @@ impl AsyncStorage {
124120
config: Arc<Config>,
125121
) -> Result<Self> {
126122
Ok(Self {
127-
sqlite_pool: Arc::new(SqliteConnectionPool::new(
128-
NonZeroU64::new(config.max_sqlite_pool_size)
129-
.ok_or_else(|| anyhow!("invalid sqlite pool size"))?,
130-
)),
131123
config: config.clone(),
132124
backend: match config.storage_backend {
133125
StorageKind::Database => {
@@ -239,10 +231,9 @@ impl AsyncStorage {
239231
pub(crate) async fn exists_in_archive(&self, archive_path: &str, path: &str) -> Result<bool> {
240232
match self.get_index_filename(archive_path).await {
241233
Ok(index_filename) => Ok({
242-
let sqlite_pool = self.sqlite_pool.clone();
243234
let path = path.to_owned();
244235
spawn_blocking(move || {
245-
Ok(archive_index::find_in_file(index_filename, &path, &sqlite_pool)?.is_some())
236+
Ok(archive_index::find_in_file(index_filename, &path)?.is_some())
246237
})
247238
.await?
248239
}),
@@ -333,10 +324,8 @@ impl AsyncStorage {
333324
}
334325
let index_filename = self.get_index_filename(archive_path).await?;
335326
let info = {
336-
let sqlite_pool = self.sqlite_pool.clone();
337327
let path = path.to_owned();
338-
spawn_blocking(move || archive_index::find_in_file(index_filename, &path, &sqlite_pool))
339-
.await
328+
spawn_blocking(move || archive_index::find_in_file(index_filename, &path)).await
340329
}?
341330
.ok_or(PathNotFoundError)?;
342331

src/storage/sqlite_pool.rs

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

0 commit comments

Comments
 (0)