Skip to content

Commit

Permalink
Avoid unnecessary optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Nelson committed Feb 15, 2022
1 parent 2055910 commit 38ef556
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion brokers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
arcstr = "1.1"
deadpool-redis = { version = "0.9", optional = true }
lapin = { version = "1.1", optional = true }
env_logger = "0.7"
Expand Down
12 changes: 6 additions & 6 deletions brokers/src/redis.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{
fmt::{self, Debug},
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};

use arcstr::ArcStr;
pub use deadpool_redis;
use deadpool_redis::{
redis::{
Expand Down Expand Up @@ -39,9 +39,9 @@ const STREAM_TIMEOUT_KEY: &'static str = "timeout_at";
pub struct RedisBroker {
/// The consumer name of this broker. Should be unique to the container/machine consuming
/// messages.
pub name: ArcStr,
pub name: Arc<str>,
/// The consumer group name.
pub group: ArcStr,
pub group: Arc<str>,
/// The largest chunk to consume from Redis. This is only exposed for tuning purposes and
/// doesn't affect the public API at all.
pub max_chunk: usize,
Expand Down Expand Up @@ -89,7 +89,7 @@ impl RedisBroker {
}

/// Creates a new broker with sensible defaults.
pub fn new(group: impl Into<ArcStr>, pool: Pool, address: &str) -> RedisBroker {
pub fn new(group: impl Into<Arc<str>>, pool: Pool, address: &str) -> RedisBroker {
let group = group.into();
let name = nanoid!();
let read_opts = RedisBroker::make_read_opts(&*group, &name);
Expand Down Expand Up @@ -190,7 +190,7 @@ impl RedisBroker {
.iter()
.copied()
.map(|event| {
let event = ArcStr::from(event);
let event = Arc::<str>::from(event);
let group = group.clone();
let name = name.clone();

Expand Down Expand Up @@ -247,7 +247,7 @@ impl RedisBroker {
let messages = read.map(|reply| reply.keys).into_iter().flatten().flat_map(
move |event| {
let group = group.clone();
let key = ArcStr::from(event.key);
let key = Arc::<str>::from(event.key);
event.ids.into_iter().map(move |id| {
Ok(Message::<V>::new(
id,
Expand Down
12 changes: 7 additions & 5 deletions brokers/src/redis/message.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use std::{
sync::Arc,
time::{Duration, SystemTime, UNIX_EPOCH},
};

use arcstr::ArcStr;
use redis::{streams::StreamId, AsyncCommands};
use serde::{de::DeserializeOwned, Serialize};

Expand All @@ -12,9 +14,9 @@ use super::{RedisBroker, STREAM_DATA_KEY, STREAM_TIMEOUT_KEY};
#[derive(Debug)]
pub struct Message<V> {
/// The group this message belongs to.
pub group: ArcStr,
pub group: Arc<str>,
/// The event this message signals.
pub event: ArcStr,
pub event: Arc<str>,
/// The ID of this message (generated by Redis).
pub id: String,
/// The data of this message. Always present unless there is a bug with a client implementation.
Expand All @@ -37,7 +39,7 @@ impl<V> Message<V>
where
V: DeserializeOwned,
{
pub(crate) fn new(id: StreamId, group: ArcStr, event: ArcStr, broker: RedisBroker) -> Self {
pub(crate) fn new(id: StreamId, group: Arc<str>, event: Arc<str>, broker: RedisBroker) -> Self {
let data = id
.get(STREAM_DATA_KEY)
.and_then(|data: Vec<u8>| rmp_serde::from_read_ref(&data).ok());
Expand Down

0 comments on commit 38ef556

Please sign in to comment.