Skip to content

Commit

Permalink
Remove unnecessary channel_name helper (#409)
Browse files Browse the repository at this point in the history
Closes #391
  • Loading branch information
DanGould authored Nov 26, 2024
2 parents 6a0f4ce + 3fa3b3b commit 49339c0
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions payjoin-directory/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl DbPool {
data: Vec<u8>,
) -> RedisResult<()> {
let mut conn = self.client.get_async_connection().await?;
let key = channel_name(pubkey_id, channel_type);
let key = pubkey_id.column_key(channel_type);
() = conn.set(&key, data.clone()).await?;
() = conn.publish(&key, "updated").await?;
Ok(())
Expand All @@ -71,7 +71,7 @@ impl DbPool {

async fn peek(&self, pubkey_id: &ShortId, channel_type: &str) -> RedisResult<Vec<u8>> {
let mut conn = self.client.get_async_connection().await?;
let key = channel_name(pubkey_id, channel_type);
let key = pubkey_id.column_key(channel_type);

// Attempt to fetch existing content for the given pubkey_id and channel_type
if let Ok(data) = conn.get::<_, Vec<u8>>(&key).await {
Expand All @@ -83,7 +83,7 @@ impl DbPool {

// Set up a temporary listener for changes
let mut pubsub_conn = self.client.get_async_connection().await?.into_pubsub();
let channel_name = channel_name(pubkey_id, channel_type);
let channel_name = pubkey_id.column_key(channel_type);
pubsub_conn.subscribe(&channel_name).await?;

// Use a block to limit the scope of the mutable borrow
Expand Down Expand Up @@ -116,7 +116,3 @@ impl DbPool {
Ok(data)
}
}

fn channel_name(pubkey_id: &ShortId, channel_type: &str) -> Vec<u8> {
pubkey_id.column_key(channel_type)
}

0 comments on commit 49339c0

Please sign in to comment.