paginate select when initializing search index

This commit is contained in:
trinity-1686a 2024-01-31 22:08:21 +01:00
parent 304fb740d8
commit 4f848ca278
1 changed files with 20 additions and 6 deletions

View File

@ -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 = 1000;
let mut count = 0;
loop {
let posts = posts::table
.filter(posts::published.eq(true))
.order(posts::id.asc())
.limit(PAGE_SIZE)
.offset(count)
.load::<Post>(conn)?;
for post in posts.iter() {
self.add_document(conn, post)?
}
if posts.len() < PAGE_SIZE as usize {
break Ok(())
}
count += posts.len();
}
Ok(())
}
pub fn commit(&self) {