A decentralized music tracking and discovery platform built on AT Protocol 🎵

[scrobbler] avoid duplicate scrobbles

+68 -9
+1
crates/scrobbler/src/repo/mod.rs
··· 1 1 pub mod album; 2 2 pub mod api_key; 3 3 pub mod artist; 4 + pub mod spotify_account; 4 5 pub mod spotify_token; 5 6 pub mod track; 6 7 pub mod user;
+26
crates/scrobbler/src/repo/spotify_account.rs
··· 1 + use anyhow::Error; 2 + use sqlx::{Pool, Postgres}; 3 + 4 + use crate::xata::spotify_account::SpotifyAccount; 5 + 6 + pub async fn get_spotify_account( 7 + pool: &Pool<Postgres>, 8 + did: &str, 9 + ) -> Result<Option<SpotifyAccount>, Error> { 10 + let results: Vec<SpotifyAccount> = sqlx::query_as( 11 + r#" 12 + SELECT * FROM spotify_accounts 13 + LEFT JOIN users ON spotify_accounts.user_id = users.xata_id 14 + WHERE users.did = $1 15 + "#, 16 + ) 17 + .bind(did) 18 + .fetch_all(pool) 19 + .await?; 20 + 21 + if results.len() == 0 { 22 + return Ok(None); 23 + } 24 + 25 + Ok(Some(results[0].clone())) 26 + }
+25
crates/scrobbler/src/scrobbler.rs
··· 489 489 ); 490 490 return Ok(()); 491 491 } 492 + 493 + let spotify_user = repo::spotify_account::get_spotify_account(pool, &did).await?; 494 + if let Some(spotify_user) = spotify_user { 495 + if cache.get(&format!("{}:current", spotify_user.email))?.is_some() { 496 + println!( 497 + "{} {} - {}, currently scrobbling, skipping", 498 + "Currently scrobbling: ".yellow(), 499 + artist, 500 + track 501 + ); 502 + return Ok(()); 503 + } 504 + } 505 + 506 + if cache.get(&format!("nowplaying:{}", did))?.is_some() { 507 + println!( 508 + "{} {} - {}, currently scrobbling, skipping", 509 + "Currently scrobbling: ".yellow(), 510 + artist, 511 + track 512 + ); 513 + return Ok(()); 514 + } 515 + 516 + 492 517 // set cache for 5 seconds to avoid duplicate scrobbles 493 518 cache.setex( 494 519 &format!("listenbrainz:cache:{}:{}:{}", artist, track, did),
+6 -9
rockskyweb/src/components/ScrobblesAreaChart/ScrobblesAreaChart.tsx
··· 13 13 }: TooltipProps<number, string>) => { 14 14 if (active && payload && payload.length) { 15 15 return ( 16 - <div 17 - style={{ 18 - backgroundColor: "white", 19 - padding: "5px", 20 - border: "1px solid #ccc", 21 - }} 22 - > 23 - <span style={{ color: "#808080" }}> 16 + <div className="bg-[#fff] border-[1px] border-[#ccc] p-[5px]"> 17 + <span className="text-[#808080]"> 24 18 {dayjs(label).format("dddd DD MMMM YYYY")}: 25 19 </span> 26 - <span> {numeral(payload[0].value).format("0,0")}</span> 20 + <span className="text-[#710de4]"> 21 + {" "} 22 + {numeral(payload[0].value).format("0,0")} 23 + </span> 27 24 </div> 28 25 ); 29 26 }
+10
rockskyweb/src/pages/profile/library/albums/Albums.tsx
··· 135 135 }, 136 136 }, 137 137 }, 138 + TableEmptyMessage: { 139 + style: { 140 + backgroundColor: "var(--color-background)", 141 + }, 142 + }, 143 + Table: { 144 + style: { 145 + backgroundColor: "var(--color-background)", 146 + }, 147 + }, 138 148 }} 139 149 > 140 150 <TableBuilderColumn header="Name">