Skip to content

Commit

Permalink
opt(torii-grpc): entity updated after on entities table (#2810)
Browse files Browse the repository at this point in the history
* opt(torii-grpc): entity updated after on entities table

* fix: query

* refactor: clean up code and fix total counts

* fmt

* fmt

* clippy
  • Loading branch information
Larkooo authored Dec 16, 2024
1 parent 8111b6d commit b0e9367
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 86 deletions.
19 changes: 0 additions & 19 deletions crates/torii/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ pub fn build_sql_query(
order_by: Option<&str>,
limit: Option<u32>,
offset: Option<u32>,
internal_updated_at: u64,
) -> Result<(String, String), Error> {
fn collect_columns(table_prefix: &str, path: &str, ty: &Ty, selections: &mut Vec<String>) {
match ty {
Expand Down Expand Up @@ -174,7 +173,6 @@ pub fn build_sql_query(
selections.push(format!("{}.id", table_name));
selections.push(format!("{}.keys", table_name));

let mut internal_updated_at_clause = Vec::with_capacity(schemas.len());
// Process each model schema
for model in schemas {
let model_table = model.name();
Expand All @@ -183,10 +181,6 @@ pub fn build_sql_query(
[{model_table}].{entity_relation_column}",
));

if internal_updated_at > 0 {
internal_updated_at_clause.push(format!("[{model_table}].internal_updated_at >= ?"));
}

// Collect columns with table prefix
collect_columns(&model_table, "", model, &mut selections);
}
Expand All @@ -204,18 +198,6 @@ pub fn build_sql_query(
count_query += &format!(" WHERE {}", where_clause);
}

if !internal_updated_at_clause.is_empty() {
if where_clause.is_none() {
query += " WHERE ";
count_query += " WHERE ";
} else {
query += " AND ";
count_query += " AND ";
}
query += &format!(" {}", internal_updated_at_clause.join(" AND "));
count_query += &format!(" {}", internal_updated_at_clause.join(" AND "));
}

// Use custom order by if provided, otherwise default to event_id DESC
if let Some(order_clause) = order_by {
query += &format!(" ORDER BY {}", order_clause);
Expand Down Expand Up @@ -513,7 +495,6 @@ mod tests {
None,
None,
None,
0,
)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion crates/torii/grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ message Query {
bool dont_include_hashed_keys = 4;
repeated OrderBy order_by = 5;
repeated string entity_models = 6;
uint64 internal_updated_at = 7;
uint64 entity_updated_after = 7;
}

message EventQuery {
Expand Down
Loading

0 comments on commit b0e9367

Please sign in to comment.