From 61d119aedd12e7107fdd43c689a7b500a271c421 Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Fri, 24 Apr 2020 14:24:33 -0400 Subject: [PATCH] Fix redis_namespace bug This fixes a bug that would cause Redis commands not to be sent properly when users had set the REDIS_NAMESPACE environmental variable. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/response/event.rs | 2 +- src/response/redis/connection.rs | 17 +++++++++++------ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8ae62a7..d3c4761 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,7 +416,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "flodgatt" -version = "0.9.2" +version = "0.9.3" dependencies = [ "criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 6946bf4..7437aee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "flodgatt" description = "A blazingly fast drop-in replacement for the Mastodon streaming api server" -version = "0.9.2" +version = "0.9.3" authors = ["Daniel Long Sockwell "] edition = "2018" diff --git a/src/response/event.rs b/src/response/event.rs index 37c7af1..6220981 100644 --- a/src/response/event.rs +++ b/src/response/event.rs @@ -103,7 +103,7 @@ impl Event { Conversation { payload, .. } => Some(escaped(payload)), Announcement { payload, .. } => Some(escaped(payload)), AnnouncementReaction { payload, .. } => Some(escaped(payload)), - AnnouncementDelete { payload, .. } => Some(payload.clone()), + AnnouncementDelete { payload, .. } | Delete { payload, .. } => Some(payload.clone()), FiltersChanged => None, }, diff --git a/src/response/redis/connection.rs b/src/response/redis/connection.rs index 1ac980b..acdc794 100644 --- a/src/response/redis/connection.rs +++ b/src/response/redis/connection.rs @@ -73,7 +73,7 @@ impl RedisConn { let input = &self.redis_input[..self.cursor]; let (input, invalid_bytes) = str::from_utf8(&input) - .map(|input| (input, &b""[..])) + .map(|input| (input, "".as_bytes())) .unwrap_or_else(|e| { let (valid, invalid) = input.split_at(e.valid_up_to()); (str::from_utf8(valid).expect("Guaranteed by ^^^^"), invalid) @@ -117,18 +117,23 @@ impl RedisConn { } pub(crate) fn send_cmd(&mut self, cmd: RedisCmd, timeline: &Timeline) -> Result<()> { + let namespace = self.redis_namespace.take(); let hashtag = timeline.tag().and_then(|id| self.tag_name_cache.get(&id)); - let tl = timeline.to_redis_raw_timeline(hashtag)?; + let tl = match &namespace { + Some(ns) => format!("{}:{}", ns, timeline.to_redis_raw_timeline(hashtag)?), + None => timeline.to_redis_raw_timeline(hashtag)?, + }; let (primary_cmd, secondary_cmd) = cmd.into_sendable(&tl); self.primary.write_all(&primary_cmd)?; - // We also need to set a key to tell the Puma server that we've subscribed - // or unsubscribed to the channel because it stops publishing updates when it - // thinks no one is subscribed. (Documented in [PR - // #3278](https://github.com/tootsuite/mastodon/pull/3278)) + // We also need to set a key to tell the Puma server that we've subscribed or + // unsubscribed to the channel because it stops publishing updates when it thinks + // no one is subscribed. + // (Documented in [PR #3278](https://github.com/tootsuite/mastodon/pull/3278)) // Question: why can't the Puma server just use NUMSUB for this? self.secondary.write_all(&secondary_cmd)?; + log::info!("Sent {}", String::from_utf8_lossy(&secondary_cmd)); Ok(()) }