Skip to content

Commit 78dcb42

Browse files
Nemo157Joshua Nelson
authored andcommitted
Don't keep the index repository open long term
1 parent 8b5fb70 commit 78dcb42

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/docbuilder/queue.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ impl DocBuilder {
1212
/// Returns the number of crates added
1313
pub fn get_new_crates(&mut self) -> Result<usize> {
1414
let conn = connect_db()?;
15-
let (mut changes, oid) = self.index.diff().peek_changes()?;
15+
let diff = self.index.diff()?;
16+
let (mut changes, oid) = diff.peek_changes()?;
1617
let mut crates_added = 0;
1718

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

61-
self.index.diff().set_last_seen_reference(oid)?;
62+
diff.set_last_seen_reference(oid)?;
6263

6364
Ok(crates_added)
6465
}

src/index/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use url::Url;
44

55
use self::api::Api;
66
use crate::error::Result;
7+
use failure::ResultExt;
78

89
pub(crate) mod api;
910

1011
pub(crate) struct Index {
11-
diff: crates_index_diff::Index,
1212
path: PathBuf,
1313
api: Api,
1414
}
@@ -41,14 +41,17 @@ fn load_config(repo: &git2::Repository) -> Result<IndexConfig> {
4141
impl Index {
4242
pub(crate) fn new(path: impl AsRef<Path>) -> Result<Self> {
4343
let path = path.as_ref().to_owned();
44-
let diff = crates_index_diff::Index::from_path_or_cloned(&path)?;
45-
let config = load_config(diff.repository())?;
46-
let api = Api::new(config.api)?;
47-
Ok(Self { diff, path, api })
44+
let diff = crates_index_diff::Index::from_path_or_cloned(&path)
45+
.context("initialising registry index repository")?;
46+
let config = load_config(diff.repository()).context("loading registry config")?;
47+
let api = Api::new(config.api).context("initialising registry api client")?;
48+
Ok(Self { path, api })
4849
}
4950

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

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

0 commit comments

Comments
 (0)