Skip to content

Commit

Permalink
use IterAsTuple::chunks more and chunks.len() => chunks.element_count()
Browse files Browse the repository at this point in the history
  • Loading branch information
rustonaut committed Aug 7, 2023
1 parent 999d659 commit 1949427
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions web-api/src/storage/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ impl Database {
let mut builder = QueryBuilder::new("DELETE FROM document WHERE document_id IN ");
let all = ids.into_iter();
let mut deleted = Vec::with_capacity(all.len());
let mut ids = all.clone();
while let Ok(ids) = IterAsTuple::new(ids.by_ref().take(Self::BIND_LIMIT)) {
let mut chunks = IterAsTuple::chunks(Self::BIND_LIMIT, all.clone());
while let Some(ids) = chunks.next() {
deleted.extend(
builder
.reset()
Expand Down Expand Up @@ -227,7 +227,7 @@ impl Database {
WHERE document_id IN ",
);
let mut chunks = IterAsTuple::chunks(Self::BIND_LIMIT, ids);
let mut documents = Vec::with_capacity(chunks.len());
let mut documents = Vec::with_capacity(chunks.element_count());
while let Some(ids) = chunks.next() {
documents.extend(
builder
Expand Down Expand Up @@ -267,8 +267,9 @@ impl Database {
include_snippet.then_some(", snippet").unwrap_or_default(),
));
let mut documents = Vec::with_capacity(scores.len());
let mut ids = scores.keys().map(SnippetId::document_id);
while let Ok(ids) = IterAsTuple::new(ids.by_ref().take(Self::BIND_LIMIT)) {
let mut chunks =
IterAsTuple::chunks(Self::BIND_LIMIT, scores.keys().map(SnippetId::document_id));
while let Some(ids) = chunks.next() {
documents.extend(
builder
.reset()
Expand Down Expand Up @@ -320,9 +321,9 @@ impl Database {
FROM document
WHERE document_id IN ",
);
let mut ids = ids.into_iter();
let mut documents = Vec::with_capacity(ids.len());
while let Ok(ids) = IterAsTuple::new(ids.by_ref().take(Self::BIND_LIMIT)) {
let mut chunks = IterAsTuple::chunks(Self::BIND_LIMIT, ids);
let mut documents = Vec::with_capacity(chunks.element_count());
while let Some(ids) = chunks.next() {
documents.extend(
builder
.reset()
Expand Down
2 changes: 1 addition & 1 deletion web-api/src/storage/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ where
IterAsTuple::new(self.iter.by_ref().take(self.chunk_size)).ok()
}

pub(super) fn len(&self) -> usize
pub(super) fn element_count(&self) -> usize
where
I: ExactSizeIterator,
{
Expand Down

0 comments on commit 1949427

Please sign in to comment.