mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-21 19:11:04 +00:00
paginate select when initializing search index
This commit is contained in:
parent
304fb740d8
commit
4f848ca278
1 changed files with 20 additions and 6 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue