Skip to content

Commit ae6a837

Browse files
author
trinity-1686a
committed
Merge pull request 'paginate select when initializing search index' (#1153) from paginate-search-init into main
2 parents b486178 + 408d53e commit ae6a837

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

plume-models/src/search/searcher.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,27 @@ Then try to restart Plume
289289
}
290290

291291
pub fn fill(&self, conn: &Connection) -> Result<()> {
292-
for post in posts::table
293-
.filter(posts::published.eq(true))
294-
.load::<Post>(conn)?
295-
{
296-
self.update_document(conn, &post)?
292+
let mut writer = self.writer.lock().unwrap();
293+
let writer = writer.as_mut().unwrap();
294+
writer.delete_all_documents().unwrap();
295+
296+
const PAGE_SIZE: i64 = 8192;
297+
let mut cursor = -1;
298+
loop {
299+
let posts = posts::table
300+
.filter(posts::published.eq(true))
301+
.filter(posts::id.gt(cursor))
302+
.order(posts::id.asc())
303+
.limit(PAGE_SIZE)
304+
.load::<Post>(conn)?;
305+
for post in posts.iter() {
306+
self.add_document(conn, post)?;
307+
cursor = post.id;
308+
}
309+
if posts.len() < PAGE_SIZE as usize {
310+
break Ok(())
311+
}
297312
}
298-
Ok(())
299313
}
300314

301315
pub fn commit(&self) {

0 commit comments

Comments
 (0)