diff --git a/src/domain/account_info.rs b/src/domain/account_info.rs index 2577061..09ca378 100644 --- a/src/domain/account_info.rs +++ b/src/domain/account_info.rs @@ -64,6 +64,21 @@ impl From<&PublicKey> for FriendlyId { } } +impl FriendlyId { + pub fn enriched_display(&self, npub: Option<&str>) -> String { + match self { + FriendlyId::Npub(_) | FriendlyId::PublicKey(_) => self.to_string(), + _ => { + if let Some(npub) = npub { + format!("{} ({})", self, npub) + } else { + self.to_string() + } + } + } + } +} + #[derive(Debug, Clone)] pub struct AccountInfo { pub public_key: PublicKey, diff --git a/src/domain/follow_change.rs b/src/domain/follow_change.rs index 0cd13b8..4b70cab 100644 --- a/src/domain/follow_change.rs +++ b/src/domain/follow_change.rs @@ -112,6 +112,16 @@ impl FollowChange { pub fn followed_at(&self) -> DateTime { self.followed_at } + + pub fn enriched_follower_display(&self) -> String { + let npub = self.follower.to_bech32().ok(); + self.friendly_follower.enriched_display(npub.as_deref()) + } + + pub fn enriched_followee_display(&self) -> String { + let npub = self.followee.to_bech32().ok(); + self.friendly_followee.enriched_display(npub.as_deref()) + } } impl fmt::Display for FollowChange { diff --git a/src/domain/notification_factory.rs b/src/domain/notification_factory.rs index 326a26b..2698eb4 100644 --- a/src/domain/notification_factory.rs +++ b/src/domain/notification_factory.rs @@ -38,13 +38,6 @@ impl NotificationFactory { // lower values cause faster forgetting of infrequent items) let top_followees: TopK> = TopK::new(100, 500, 3, 0.5); - // Initialize metrics with 0 values - for node in top_followees.list() { - if let Ok(friendly_id) = String::from_utf8(node.item.to_vec()) { - metrics::top_followee_count(friendly_id).set(0.0); - } - } - Self { followee_maps: OrderMap::with_capacity(1_000), burst, @@ -61,10 +54,9 @@ impl NotificationFactory { FolloweeNotificationFactory::new(self.burst, self.min_seconds_between_messages) }); - // Add to TopK tracking when it's a follow (not unfollow) + // Add to TopK tracking only when it's a follow (not unfollow) if follow_change.is_follower() { - // Convert friendly_followee to bytes for TopK tracking - let friendly_id = follow_change.friendly_followee().to_string(); + let friendly_id = follow_change.enriched_followee_display(); self.top_followees.add(friendly_id.as_bytes().to_vec()); } @@ -142,8 +134,8 @@ impl NotificationFactory { info!("Top 100 most followed accounts:"); for node in self.top_followees.list() { - if let Ok(friendly_id) = String::from_utf8(node.item.to_vec()) { - metrics::top_followee_count(friendly_id.clone()).set(node.count as f64); + if let Ok(id_str) = String::from_utf8(node.item.to_vec()) { + info!(" {}: {} follows", id_str, node.count); } } } diff --git a/src/metrics.rs b/src/metrics.rs index 626a022..d1507b3 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -69,10 +69,6 @@ pub fn pagerank_seconds() -> Gauge { metrics::gauge!("pagerank_seconds") } -pub fn top_followee_count(followee_id: String) -> Gauge { - metrics::gauge!("top_followee_count", "followee" => followee_id) -} - pub fn setup_metrics() -> Result { describe_counter!( "pubsub_messages", @@ -122,7 +118,6 @@ pub fn setup_metrics() -> Result { "Number of retained follow changes" ); describe_gauge!("pagerank_seconds", "Seconds it takes to calculate pagerank"); - describe_gauge!("top_followee_count", "Number of follows for top followees"); let prometheus_builder = PrometheusBuilder::new(); let prometheus_handle = prometheus_builder.install_recorder()?;