Skip to content

Don't keep the index repository open long term #847

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

Merged
merged 2 commits into from
Jun 22, 2020
Merged
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
5 changes: 3 additions & 2 deletions src/docbuilder/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ impl DocBuilder {
/// Returns the number of crates added
pub fn get_new_crates(&mut self) -> Result<usize> {
let conn = connect_db()?;
let (mut changes, oid) = self.index.diff().peek_changes()?;
let diff = self.index.diff()?;
let (mut changes, oid) = diff.peek_changes()?;
let mut crates_added = 0;

// I believe this will fix ordering of queue if we get more than one crate from changes
Expand Down Expand Up @@ -58,7 +59,7 @@ impl DocBuilder {
}
}

self.index.diff().set_last_seen_reference(oid)?;
diff.set_last_seen_reference(oid)?;

Ok(crates_added)
}
Expand Down
19 changes: 12 additions & 7 deletions src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use url::Url;

use self::api::Api;
use crate::error::Result;
use failure::ResultExt;

pub(crate) mod api;

pub(crate) struct Index {
diff: crates_index_diff::Index,
path: PathBuf,
api: Api,
}
Expand Down Expand Up @@ -41,14 +41,19 @@ fn load_config(repo: &git2::Repository) -> Result<IndexConfig> {
impl Index {
pub(crate) fn new(path: impl AsRef<Path>) -> Result<Self> {
let path = path.as_ref().to_owned();
let diff = crates_index_diff::Index::from_path_or_cloned(&path)?;
let config = load_config(diff.repository())?;
let api = Api::new(config.api)?;
Ok(Self { diff, path, api })
// This initializes the repository, then closes it afterwards to avoid leaking file descriptors.
// See https://github.com/rust-lang/docs.rs/pull/847
let diff = crates_index_diff::Index::from_path_or_cloned(&path)
.context("initialising registry index repository")?;
let config = load_config(diff.repository()).context("loading registry config")?;
let api = Api::new(config.api).context("initialising registry api client")?;
Ok(Self { path, api })
}

pub(crate) fn diff(&self) -> &crates_index_diff::Index {
&self.diff
pub(crate) fn diff(&self) -> Result<crates_index_diff::Index> {
let diff = crates_index_diff::Index::from_path_or_cloned(&self.path)
.context("re-opening registry index for diff")?;
Ok(diff)
}

pub(crate) fn api(&self) -> &Api {
Expand Down