Skip to content

Commit

Permalink
Merge pull request 'paginate select when initializing search index' (…
Browse files Browse the repository at this point in the history
…#1153) from paginate-search-init into main
  • Loading branch information
trinity-1686a committed Jan 25, 2025
2 parents b486178 + 408d53e commit ae6a837
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions plume-models/src/search/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,27 @@ Then try to restart Plume
}

pub fn fill(&self, conn: &Connection) -> Result<()> {
for post in posts::table
.filter(posts::published.eq(true))
.load::<Post>(conn)?
{
self.update_document(conn, &post)?
let mut writer = self.writer.lock().unwrap();
let writer = writer.as_mut().unwrap();
writer.delete_all_documents().unwrap();

const PAGE_SIZE: i64 = 8192;
let mut cursor = -1;
loop {
let posts = posts::table
.filter(posts::published.eq(true))
.filter(posts::id.gt(cursor))
.order(posts::id.asc())
.limit(PAGE_SIZE)
.load::<Post>(conn)?;
for post in posts.iter() {
self.add_document(conn, post)?;
cursor = post.id;
}
if posts.len() < PAGE_SIZE as usize {
break Ok(())
}
}
Ok(())
}

pub fn commit(&self) {
Expand Down

0 comments on commit ae6a837

Please sign in to comment.