tangled
alpha
login
or
join now
cherry.computer
/
website
0
fork
atom
My personal site
cherry.computer
htmx
tailwind
axum
askama
0
fork
atom
overview
issues
pulls
pipelines
feat: only send scrobble if the song has changed
cherry.computer
1 year ago
579656b8
f59d41be
verified
This commit was signed with the committer's
known signature
.
cherry.computer
SSH Key Fingerprint:
SHA256:SIA77Ll0IpMb8Xd3RtaGT+PBIGIePhJJg5W2r6Td7cc=
+17
-3
2 changed files
expand all
collapse all
unified
split
server
src
main.rs
scrobble.rs
+16
-2
server/src/main.rs
reviewed
···
73
73
Query(ScrobbleQuery { immediate }): Query<ScrobbleQuery>,
74
74
) -> Sse<impl Stream<Item = Result<sse::Event, Infallible>>> {
75
75
let stream = stream! {
76
76
+
let mut last_template = None;
77
77
+
76
78
let mut interval = time::interval(Duration::from_secs(30));
77
79
interval.set_missed_tick_behavior(MissedTickBehavior::Skip);
78
80
if !immediate {
79
81
interval.tick().await;
82
82
+
last_template = monitor.get_scrobble().await.ok();
80
83
}
84
84
+
81
85
loop {
82
86
interval.tick().await;
83
83
-
let template = match monitor.get_scrobble().await {
87
87
+
let new_template = match monitor.get_scrobble().await {
84
88
Ok(template) => template,
85
89
Err(err) => {
86
90
tracing::error!("failed to get data from last.fm: {err:?}");
87
91
continue;
88
92
}
89
93
};
90
90
-
let data = match template.render() {
94
94
+
95
95
+
if last_template
96
96
+
.as_ref()
97
97
+
.is_some_and(|last_template| last_template == &new_template)
98
98
+
{
99
99
+
continue;
100
100
+
}
101
101
+
102
102
+
let data = match new_template.render() {
91
103
Ok(data) => data,
92
104
Err(err) => {
93
105
tracing::error!("failed to render scrobble: {err:?}");
···
95
107
}
96
108
};
97
109
yield Ok(sse::Event::default().event("scrobble").data(data));
110
110
+
111
111
+
last_template.replace(new_template);
98
112
}
99
113
};
100
114
+1
-1
server/src/scrobble.rs
reviewed
···
39
39
pub recent_tracks: ScrobbleRecentTracks,
40
40
}
41
41
42
42
-
#[derive(Template, Debug, Clone)]
42
42
+
#[derive(Template, Debug, Clone, PartialEq)]
43
43
#[template(path = "scrobble.html")]
44
44
pub struct ScrobblesTemplate {
45
45
pub intro: &'static str,