Skip to content

Commit

Permalink
parsing channels only requires cells
Browse files Browse the repository at this point in the history
  • Loading branch information
pjenvey committed Jul 19, 2024
1 parent 2fb86e0 commit 13c2e12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 7 additions & 7 deletions autopush-common/src/db/bigtable/bigtable_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::db::{
};

pub use self::metadata::MetadataBuilder;
use self::row::Row;
use self::row::{Cells, Row};
use super::pool::BigTablePool;
use super::BigTableDbSettings;

Expand Down Expand Up @@ -204,10 +204,10 @@ fn to_string(value: Vec<u8>, name: &str) -> Result<String, DbError> {

/// Parse the "set" (see [DbClient::add_channels]) of channel ids in a bigtable Row.
///
/// The row should solely contain the set of channels otherwise an Error is returned.
fn channels_from_row(row: &row::Row) -> DbResult<HashSet<Uuid>> {
/// Cells should solely contain the set of channels otherwise an Error is returned.
fn channels_from_cells(cells: &Cells) -> DbResult<HashSet<Uuid>> {
let mut result = HashSet::new();
for cells in row.cells.values() {
for cells in cells.values() {
let Some(cell) = cells.last() else {
continue;
};
Expand Down Expand Up @@ -322,7 +322,7 @@ pub fn retryable_error(metrics: Arc<StatsdClient>) -> impl Fn(&grpcio::Error) ->
/// 2) When router TTLs are eventually enabled: `add_channel` and
/// `increment_storage` can write cells with later expiry times than the other
/// router cells
fn is_incomplete_router_record(cells: &HashMap<String, Vec<cell::Cell>>) -> bool {
fn is_incomplete_router_record(cells: &Cells) -> bool {
cells
.keys()
.all(|k| ["current_timestamp", "version"].contains(&k.as_str()) || k.starts_with("chid:"))
Expand Down Expand Up @@ -986,7 +986,7 @@ impl DbClient for BigTableClientImpl {
}

// Read the channels last, after removal of all non channel cells
result._channels = channels_from_row(&row)?;
result._channels = channels_from_cells(&row.cells)?;

Ok(Some(result))
}
Expand Down Expand Up @@ -1049,7 +1049,7 @@ impl DbClient for BigTableClientImpl {
let Some(row) = self.read_row(req).await? else {
return Ok(Default::default());
};
channels_from_row(&row)
channels_from_cells(&row.cells)
}

/// Delete the channel. Does not delete its associated pending messages.
Expand Down
4 changes: 3 additions & 1 deletion autopush-common/src/db/bigtable/bigtable_client/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::db::error::{DbError, DbResult};

use super::{cell::Cell, RowKey};

pub type Cells = HashMap<String, Vec<Cell>>;

/// A Bigtable storage row. Bigtable stores by Family ID which isn't
/// very useful for us later, so we overload this structure a bit.
/// When we read data back out of Bigtable, we index cells by
Expand All @@ -19,7 +21,7 @@ pub struct Row {
pub row_key: RowKey,
/// The row's collection of cells, indexed by either the
/// FamilyID (for write) or Qualifier (for read).
pub cells: HashMap<String, Vec<Cell>>,
pub cells: Cells,
}

impl Row {
Expand Down

0 comments on commit 13c2e12

Please sign in to comment.