Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(entity_access): cache channel_users and call_users (#5302)
Will Hutchinson7e6f3293120c
diff --git a/.sqlx/query-c5dec9db3fad5320c2c9b21b10934e48081577fe24ccb00932c0bd523debda92.json b/.sqlx/query-c5dec9db3fad5320c2c9b21b10934e48081577fe24ccb00932c0bd523debda92.jsonnew file mode 100644index 0000000000..c923a56dad--- /dev/null+++ b/.sqlx/query-c5dec9db3fad5320c2c9b21b10934e48081577fe24ccb00932c0bd523debda92.json@@ -0,0 +1,28 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT channel_id AS \"channel_id!\", share_permission_id AS \"share_permission_id!\"\n FROM calls\n WHERE channel_id = $1\n UNION ALL\n SELECT channel_id, share_permission_id\n FROM call_records\n WHERE channel_id = $1\n ORDER BY 1\n LIMIT 1\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "channel_id!",+ "type_info": "Uuid"+ },+ {+ "ordinal": 1,+ "name": "share_permission_id!",+ "type_info": "Text"+ }+ ],+ "parameters": {+ "Left": [+ "Uuid"+ ]+ },+ "nullable": [+ null,+ null+ ]+ },+ "hash": "c5dec9db3fad5320c2c9b21b10934e48081577fe24ccb00932c0bd523debda92"+}diff --git a/crates/entity_access/src/outbound/pg_access_repo/queries/call_channel.rs b/crates/entity_access/src/outbound/pg_access_repo/queries/call_channel.rsindex a595f03dba..0da25a5d81 100644--- a/crates/entity_access/src/outbound/pg_access_repo/queries/call_channel.rs+++ b/crates/entity_access/src/outbound/pg_access_repo/queries/call_channel.rs@@ -1,10 +1,13 @@//! Queries for resolving a call to its channel ID and share permission ID.+#[cfg(not(test))]+use cached::proc_macro::cached;+use sqlx::PgPool;use uuid::Uuid;/// Row returned by call channel queries.-#[derive(sqlx::FromRow)]+#[derive(Clone, sqlx::FromRow)]pub struct CallChannelRow {/// The channel the call belongs to.pub channel_id: Uuid,@@ -43,25 +46,34 @@ pub async fn get_call_channel(/// Checks both active calls and archived call records./// Active calls are checked first.#[tracing::instrument(err, skip(pool))]-#[allow(clippy::disallowed_methods, reason = "legacy code. fix later")]+#[cfg_attr(+ not(test),+ cached(+ time = 10,+ result = true,+ key = "String",+ convert = r#"{format!("{}", channel_id)}"#+ )+)]pub async fn get_call_channel_by_channel_id(pool: &PgPool,channel_id: &Uuid,) -> Result<Option<CallChannelRow>, sqlx::Error> {- sqlx::query_as::<_, CallChannelRow>(+ sqlx::query_as!(+ CallChannelRow,r#"- SELECT channel_id, share_permission_id+ SELECT channel_id AS "channel_id!", share_permission_id AS "share_permission_id!"FROM callsWHERE channel_id = $1UNION ALLSELECT channel_id, share_permission_idFROM call_recordsWHERE channel_id = $1- ORDER BY channel_id+ ORDER BY 1LIMIT 1"#,+ channel_id)- .bind(channel_id).fetch_optional(pool).await}diff --git a/crates/entity_access/src/outbound/pg_access_repo/queries/channel_users.rs b/crates/entity_access/src/outbound/pg_access_repo/queries/channel_users.rsindex 6d32af7629..bb003ad5b6 100644--- a/crates/entity_access/src/outbound/pg_access_repo/queries/channel_users.rs+++ b/crates/entity_access/src/outbound/pg_access_repo/queries/channel_users.rs@@ -1,11 +1,23 @@//! Query for users in a channel via comms_channel_participants.+#[cfg(not(test))]+use cached::proc_macro::cached;+use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};use sqlx::PgPool;use uuid::Uuid;/// Get all user IDs that are active participants in a channel.#[tracing::instrument(err, skip(pool))]+#[cfg_attr(+ not(test),+ cached(+ time = 10,+ result = true,+ key = "String",+ convert = r#"{format!("{}", channel_id)}"#+ )+)]pub async fn get_channel_users(pool: &PgPool,channel_id: &Uuid,