open less repos when reindexing

This commit is contained in:
Nikita Galaiko 2023-10-20 15:01:43 +02:00 committed by GitButler
parent 2b68cd23ce
commit 638620337e
2 changed files with 13 additions and 2 deletions

View File

@ -83,7 +83,7 @@ impl Handler {
let sessions_iter = gb_repository.get_sessions_iterator()?;
let mut events = vec![];
for session in sessions_iter {
events.extend(self.index_session(project_id, &session?)?);
events.extend(self.process_session(&gb_repository, &session?)?);
}
Ok(events)
}
@ -104,10 +104,20 @@ impl Handler {
)
.context("failed to open repository")?;
self.process_session(&gb_repository, session)
}
fn process_session(
&self,
gb_repository: &gb_repository::Repository,
session: &sessions::Session,
) -> Result<Vec<events::Event>> {
let project_id = gb_repository.get_project_id();
// index bookmarks right away. bookmarks are stored in the session during which it was
// created, not in the session that is actually bookmarked. so we want to make sure all of
// them are indexed at all times
let session_reader = sessions::Reader::open(&gb_repository, session)?;
let session_reader = sessions::Reader::open(gb_repository, session)?;
let bookmarks_reader = bookmarks::Reader::new(&session_reader);
for bookmark in bookmarks_reader.read()? {
self.index_bookmark(project_id, &bookmark)?;

View File

@ -33,6 +33,7 @@ pub struct Handler {
impl TryFrom<&AppHandle> for Handler {
type Error = anyhow::Error;
fn try_from(value: &AppHandle) -> Result<Self, Self::Error> {
Ok(Self {
events_sender: app_events::Sender::from(value),