Skip to content

Commit

Permalink
fixup: sum_packages deduplicate on package_id
Browse files Browse the repository at this point in the history
  • Loading branch information
amnn committed Nov 1, 2024
1 parent aaabb93 commit c956359
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/sui-indexer-alt/src/handlers/sum_packages.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::sync::Arc;
use std::{collections::BTreeMap, sync::Arc};

use anyhow::{anyhow, Result};
use diesel::{upsert::excluded, ExpressionMethods};
Expand Down Expand Up @@ -57,13 +57,16 @@ impl Processor for SumPackages {

#[async_trait::async_trait]
impl Handler for SumPackages {
type Batch = Vec<Self::Value>;
type Batch = BTreeMap<Vec<u8>, StoredPackage>;

fn batch(batch: &mut Self::Batch, values: Vec<Self::Value>) {
batch.extend(values);
for value in values {
batch.insert(value.package_id.clone(), value);
}
}

async fn commit(values: &Self::Batch, conn: &mut db::Connection<'_>) -> Result<usize> {
async fn commit(batch: &Self::Batch, conn: &mut db::Connection<'_>) -> Result<usize> {
let values: Vec<_> = batch.values().cloned().collect();
let updates = values.chunks(CHUNK_ROWS).map(|chunk| {
diesel::insert_into(sum_packages::table)
.values(chunk)
Expand Down

0 comments on commit c956359

Please sign in to comment.