Skip to content

Commit 381ba4a

Browse files
authored
Merge pull request #836 from RustyNova016/lazy_user_data
User data struct
2 parents ac36d41 + ca72de9 commit 381ba4a

42 files changed

Lines changed: 817 additions & 222 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 14 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ resolver = "3"
1212
[profile.dev]
1313
debug = "line-tables-only"
1414

15-
[patch]
16-
17-
[patch.crates-io]
18-
sequelles = { git = "https://github.com/RustyNova016/sequelles", rev = "f5f5df6b1669d6757cacbd5a33744f1661dbdadc"}
19-
2015
[workspace.lints.rust]
2116
unsafe_code = "forbid"
2217

alistral_cli/Cargo.toml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,19 @@ extend = "1.2.0"
3333
directories = "6.0.0"
3434
reqwest = { version = "0.12.23", features = ["json"] }
3535
rand = "0.9.2"
36-
thiserror = "2.0.17"
37-
derive_more = { version = "2.0.1", features = ["full"] }
38-
derive-new = "0.7.0"
39-
derive-getters = "0.5.0"
4036
regex = "1.11.3"
4137
sqlx = { version = "0.8.6", features = ["runtime-tokio", "macros"] }
4238
macon = "1.3.0"
43-
async-fn-stream = "0.3.0"
44-
zip = "5.1.1"
4539
indoc = "2.0.6"
4640
strsim = "0.11.1"
47-
strum_macros = "0.27.2"
4841
dotenvy = "0.15.7"
4942
url = "2.5.4"
5043

5144
# Async
5245
futures = "0.3.31"
5346
tokio = { version = "1.47.1", features = ["rt", "rt-multi-thread", "parking_lot"] }
5447
streamies = "0.2.2"
48+
async-fn-stream = "0.3.0"
5549

5650
# Cli
5751
clap = { version = "4.5.48", features = [
@@ -64,14 +58,25 @@ clap_complete = "4.5.58"
6458
clap-markdown = "0.1.5"
6559
clap-verbosity-flag = { version = "3.0.3", default-features = false, features = ["tracing"] }
6660

61+
# Error handling
62+
color-eyre = "0.6.5"
63+
thiserror = "2.0.17"
64+
65+
# Macros
66+
bon = "3.7.2"
67+
derive_more = { version = "2.0.1", features = ["full"] }
68+
derive-new = "0.7.0"
69+
derive-getters = "0.5.0"
70+
strum_macros = "0.27.2"
71+
6772
# Tracing
6873
tracing = "0.1.41"
6974
tracing-subscriber = "0.3.20"
7075
tracing-appender = "0.2.3"
7176
tracing-indicatif = "0.3.13"
72-
color-eyre = "0.6.5"
7377

7478
# Other
79+
zip = "5.1.1"
7580

7681
[features]
7782
default = ["full"]
@@ -95,6 +100,3 @@ async_fn_in_trait = { level = "allow", priority = 1 }
95100

96101
[lints.clippy]
97102
result_large_err = { level = "allow", priority = 1 }
98-
99-
[patch.crates-io]
100-
sequelles = { git = "https://github.com/RustyNova016/sequelles", rev = "f5f5df6b1669d6757cacbd5a33744f1661dbdadc"}

alistral_cli/src/database/interfaces/statistics_data.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use alistral_core::datastructures::entity_with_listens::release::collection::Rel
1212
use alistral_core::datastructures::entity_with_listens::release_group::collection::ReleaseGroupWithReleasesCollection;
1313
#[cfg(feature = "stats")]
1414
use alistral_core::datastructures::entity_with_listens::release_group::collection::ReleaseGroupWithReleasesStrategy;
15-
// use alistral_core::datastructures::entity_with_listens::work::collection::WorkWithRecordingsCollection;
16-
// use alistral_core::datastructures::entity_with_listens::work::collection::WorkWithRecordingsStrategy;
1715

1816
use crate::models::client::AlistralCliClient;
1917

@@ -23,8 +21,8 @@ pub fn artist_strategy(client: &AlistralCliClient) -> ArtistWithRecordingsStrate
2321
ArtistWithRecordingsStrategy::new(client.core.as_ref(), recording_strategy(client))
2422
}
2523

26-
pub fn recording_strategy(client: &AlistralCliClient) -> RecordingWithListenStrategy<'_> {
27-
RecordingWithListenStrategy::new(client.core.as_ref())
24+
pub fn recording_strategy(_client: &AlistralCliClient) -> RecordingWithListenStrategy {
25+
RecordingWithListenStrategy::new()
2826
}
2927

3028
#[cfg(feature = "stats")]
@@ -81,12 +79,3 @@ pub async fn release_group_stats(
8179

8280
Ok(ListenFetchQuery::get_entity_with_listens(&client.core, user, &strategy).await?)
8381
}
84-
85-
// pub async fn work_stats(
86-
// client: &AlistralCliClient,
87-
// user: String,
88-
// ) -> Result<WorkWithRecordingsCollection, crate::Error> {
89-
// let strategy = work_strategy(client);
90-
91-
// Ok(ListenFetchQuery::get_entity_with_listens(&client.core, user, &strategy).await?)
92-
// }

alistral_cli/src/datastructures/radio/seeders/listens.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl ListenSeeder {
7474
.into();
7575

7676
let mut recordings = RecordingWithListensCollection::from_listencollection(
77+
&ALISTRAL_CLIENT.core,
7778
listens,
7879
&recording_strategy(&ALISTRAL_CLIENT),
7980
)
@@ -125,6 +126,7 @@ impl ListenSeeder {
125126
.into();
126127

127128
let mapped = RecordingWithListensCollection::from_listencollection(
129+
&ALISTRAL_CLIENT.core,
128130
listens,
129131
&recording_strategy(&ALISTRAL_CLIENT),
130132
)

alistral_cli/src/models/cli/common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use core::fmt::Display;
22

3-
#[cfg(feature = "radio")]
3+
#[cfg(any(feature = "radio", feature = "lookup"))]
44
use chrono::DateTime;
5-
#[cfg(feature = "radio")]
5+
#[cfg(any(feature = "radio", feature = "lookup"))]
66
use chrono::Duration;
7-
#[cfg(feature = "radio")]
7+
#[cfg(any(feature = "radio", feature = "lookup"))]
88
use chrono::Utc;
99
use clap::ValueEnum;
1010
use derive_more::IsVariant;
@@ -67,7 +67,7 @@ pub enum Timeframe {
6767
}
6868

6969
impl Timeframe {
70-
#[cfg(feature = "radio")]
70+
#[cfg(any(feature = "radio", feature = "lookup"))]
7171
pub fn get_start_date(&self) -> DateTime<Utc> {
7272
let now = Utc::now();
7373

alistral_cli/src/models/cli/lookup/mod.rs

Lines changed: 0 additions & 39 deletions
This file was deleted.

alistral_cli/src/models/cli/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use clap_verbosity_flag::InfoLevel;
1111
use clap_verbosity_flag::Verbosity;
1212
use config::ConfigCli;
1313
use listens::ListenCommand;
14-
#[cfg(feature = "lookup")]
15-
use lookup::LookupCommand;
1614
use mapping::MappingCommand;
1715
use tuillez::fatal_error::FatalError;
1816
use unstable::UnstableCommand;
@@ -26,6 +24,8 @@ use crate::tools::bumps::bump_down_command;
2624
use crate::tools::cache::CacheCommand;
2725
use crate::tools::compatibility::compatibility_command;
2826
use crate::tools::daily::daily_report;
27+
#[cfg(feature = "lookup")]
28+
use crate::tools::lookup::LookupCommand;
2929
#[cfg(feature = "musicbrainz")]
3030
use crate::tools::musicbrainz::MusicbrainzCommand;
3131
#[cfg(feature = "interzicf")]
@@ -40,8 +40,6 @@ pub mod config;
4040
#[cfg(feature = "interzic")]
4141
pub mod interzic;
4242
pub mod listens;
43-
#[cfg(feature = "lookup")]
44-
pub mod lookup;
4543
pub mod mapping;
4644
#[cfg(feature = "radio")]
4745
pub mod radio;
@@ -205,7 +203,7 @@ impl Commands {
205203
Self::Listens(val) => val.run(conn).await?,
206204

207205
#[cfg(feature = "lookup")]
208-
Self::Lookup(val) => val.run(conn).await?,
206+
Self::Lookup(cmd) => cmd.run().await,
209207

210208
Self::Mapping(val) => val.run(conn).await?,
211209

alistral_cli/src/models/client.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use std::sync::Arc;
44
use std::sync::LazyLock;
55

66
use alistral_core::AlistralClient;
7+
use alistral_core::datastructures::entity_with_listens::recording::collection::RecordingWithListenStrategy;
8+
use alistral_core::datastructures::entity_with_listens::user::collection::UserWithListensStrategy;
79
use futures::executor::block_on;
810
#[cfg(feature = "interzicf")]
911
use interzic::InterzicClient;
@@ -134,11 +136,14 @@ impl AlistralCliClient {
134136
musicbrainz_db: Arc<DBClient>,
135137
listenbrainz: Arc<ListenbrainzClient>,
136138
) -> Arc<AlistralClient> {
137-
Arc::new(AlistralClient {
138-
listenbrainz,
139-
musicbrainz_db,
140-
offline: in_offline_mode(),
141-
})
139+
AlistralClient::builder()
140+
.listenbrainz(listenbrainz)
141+
.musicbrainz_db(musicbrainz_db)
142+
.offline(in_offline_mode())
143+
.recording_with_listen_strat(RecordingWithListenStrategy::default())
144+
.user_with_listen_strat(UserWithListensStrategy::default())
145+
.build()
146+
.into()
142147
}
143148

144149
/// Create the client, or fancy panic if an error occur

alistral_cli/src/tools/daily.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use core::cmp::Reverse;
33
use alistral_core::datastructures::entity_with_listens::artist::collection::ArtistWithRecordingsCollection;
44
use alistral_core::datastructures::listen_collection::ListenCollection;
55
use alistral_core::datastructures::listen_collection::traits::ListenCollectionReadable as _;
6+
use alistral_core::models::listen_statistics_data::ListenStatisticsData;
67
use chrono::DateTime;
78
use chrono::Datelike;
89
use chrono::NaiveDate;
@@ -18,14 +19,21 @@ use crate::ALISTRAL_CLIENT;
1819
use crate::api::listenbrainz::fresh_releases::FreshReleaseRelease;
1920
use crate::api::listenbrainz::fresh_releases::FreshReleaseRequest;
2021
use crate::database::interfaces::statistics_data::artist_strategy;
21-
use crate::database::interfaces::statistics_data::recording_stats;
2222
use crate::database::musicbrainz::anniversaries::get_recordings_aniversaries;
2323
use crate::models::config::Config;
2424
use crate::utils::constants::LISTENBRAINZ_FMT;
2525

2626
#[instrument(skip(conn))]
2727
pub async fn daily_report(conn: &mut sqlx::SqliteConnection, username: &str) {
28-
let recordings = recording_stats(&ALISTRAL_CLIENT, username.to_string())
28+
let user_data = ListenStatisticsData::new_from_user_listens(
29+
ALISTRAL_CLIENT.core.clone(),
30+
username.to_string(),
31+
)
32+
.await
33+
.expect("Couldn't fetch user listens");
34+
35+
let recordings = user_data
36+
.recording_stats()
2937
.await
3038
.expect("Couldn't fetch the listened recordings");
3139

@@ -157,6 +165,7 @@ async fn get_fresh_releases(
157165

158166
//TODO: #529 Daily: Prevent recompiling recording with listens
159167
let artists = ArtistWithRecordingsCollection::from_listencollection(
168+
&ALISTRAL_CLIENT.core,
160169
listens,
161170
&artist_strategy(&ALISTRAL_CLIENT),
162171
)

0 commit comments

Comments
 (0)