diff --git a/docs/issues/closed/1713-1525-04-split-persistence-traits.md b/docs/issues/closed/1713-1525-04-split-persistence-traits.md index 71c32a2ed..a8f2eb7fc 100644 --- a/docs/issues/closed/1713-1525-04-split-persistence-traits.md +++ b/docs/issues/closed/1713-1525-04-split-persistence-traits.md @@ -138,7 +138,7 @@ pub trait SchemaMigrator: Sync + Send { ```rust #[automock] pub trait TorrentMetricsStore: Sync + Send { - fn load_all_torrents_downloads(&self) -> Result; + fn load_all_torrents_downloads(&self) -> Result; fn load_torrent_downloads(&self, info_hash: &InfoHash) -> Result, Error>; fn save_torrent_downloads(&self, info_hash: &InfoHash, downloaded: NumberOfDownloads) -> Result<(), Error>; fn increase_downloads_for_torrent(&self, info_hash: &InfoHash) -> Result<(), Error>; @@ -224,7 +224,7 @@ impl SchemaMigrator for Sqlite { } impl TorrentMetricsStore for Sqlite { - fn load_all_torrents_downloads(&self) -> Result { ... } + fn load_all_torrents_downloads(&self) -> Result { ... } // ... remaining 6 methods } diff --git a/docs/issues/open/1669-overhaul-packages/workspace-coupling-report-2026-05-19.md b/docs/issues/open/1669-overhaul-packages/workspace-coupling-report-2026-05-19.md index 44f67bf07..e89945f46 100644 --- a/docs/issues/open/1669-overhaul-packages/workspace-coupling-report-2026-05-19.md +++ b/docs/issues/open/1669-overhaul-packages/workspace-coupling-report-2026-05-19.md @@ -242,7 +242,7 @@ Workspace deps: 9 - `torrust_tracker_primitives::AnnouncePolicy` - `torrust_tracker_primitives::NumberOfBytes` - `torrust_tracker_primitives::NumberOfDownloads` -- `torrust_tracker_primitives::NumberOfDownloadsBTreeMap` +- `torrust_tracker_primitives::NumberOfDownloadsPerInfoHash` - `torrust_tracker_primitives::PeerId` - `torrust_tracker_primitives::ScrapeData` - `torrust_tracker_primitives::pagination::Pagination` @@ -898,7 +898,7 @@ Workspace deps: 6 - `torrust_tracker_primitives::AnnounceEvent::Completed` - `torrust_tracker_primitives::AnnounceEvent::Started` - `torrust_tracker_primitives::NumberOfBytes` -- `torrust_tracker_primitives::NumberOfDownloadsBTreeMap` +- `torrust_tracker_primitives::NumberOfDownloadsPerInfoHash` - `torrust_tracker_primitives::PeerId` - `torrust_tracker_primitives::pagination::Pagination` - `torrust_tracker_primitives::peer` diff --git a/docs/issues/open/1669-overhaul-packages/workspace-coupling-report-2026-06-10.md b/docs/issues/open/1669-overhaul-packages/workspace-coupling-report-2026-06-10.md index 515191f0b..b0b2945e3 100644 --- a/docs/issues/open/1669-overhaul-packages/workspace-coupling-report-2026-06-10.md +++ b/docs/issues/open/1669-overhaul-packages/workspace-coupling-report-2026-06-10.md @@ -430,7 +430,7 @@ Workspace deps: 5 - `torrust_tracker_primitives::AnnouncePolicy` - `torrust_tracker_primitives::NumberOfBytes` - `torrust_tracker_primitives::NumberOfDownloads` -- `torrust_tracker_primitives::NumberOfDownloadsBTreeMap` +- `torrust_tracker_primitives::NumberOfDownloadsPerInfoHash` - `torrust_tracker_primitives::PeerId` - `torrust_tracker_primitives::PrivateMode` - `torrust_tracker_primitives::ScrapeData` @@ -615,7 +615,7 @@ Workspace deps: 2 - `torrust_tracker_primitives::AnnounceEvent::Completed` - `torrust_tracker_primitives::AnnounceEvent::Started` - `torrust_tracker_primitives::NumberOfBytes` -- `torrust_tracker_primitives::NumberOfDownloadsBTreeMap` +- `torrust_tracker_primitives::NumberOfDownloadsPerInfoHash` - `torrust_tracker_primitives::PeerId` - `torrust_tracker_primitives::TrackerPolicy` - `torrust_tracker_primitives::pagination::Pagination` diff --git a/docs/issues/open/1669-overhaul-packages/workspace-coupling-report-proposed-merge.md b/docs/issues/open/1669-overhaul-packages/workspace-coupling-report-proposed-merge.md index 9d7f30599..c48c9f2f7 100644 --- a/docs/issues/open/1669-overhaul-packages/workspace-coupling-report-proposed-merge.md +++ b/docs/issues/open/1669-overhaul-packages/workspace-coupling-report-proposed-merge.md @@ -248,7 +248,7 @@ _`http` feature_: - `torrust_tracker_primitives::AnnouncePolicy` - `torrust_tracker_primitives::NumberOfBytes` - `torrust_tracker_primitives::NumberOfDownloads` -- `torrust_tracker_primitives::NumberOfDownloadsBTreeMap` +- `torrust_tracker_primitives::NumberOfDownloadsPerInfoHash` - `torrust_tracker_primitives::PeerId` - `torrust_tracker_primitives::ScrapeData` - `torrust_tracker_primitives::pagination::Pagination` diff --git a/docs/issues/open/1964-rename-number-of-downloads-btree-map-type-alias.md b/docs/issues/open/1964-rename-number-of-downloads-btree-map-type-alias.md index f7365233a..0d0ca40e1 100644 --- a/docs/issues/open/1964-rename-number-of-downloads-btree-map-type-alias.md +++ b/docs/issues/open/1964-rename-number-of-downloads-btree-map-type-alias.md @@ -6,7 +6,7 @@ priority: p2 github-issue: 1964 spec-path: docs/issues/open/1964-rename-number-of-downloads-btree-map-type-alias.md branch: "1964-rename-number-of-downloads-btree-map" -related-pr: null +related-pr: "https://github.com/torrust/torrust-tracker/pull/1972" last-updated-utc: 2026-06-30 12:00 semantic-links: skill-links: @@ -79,11 +79,11 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`. | ID | Status | Task | Notes / Expected Output | | --- | ------ | ------------------------------------- | -------------------------------------------------------------------------------------------------------- | -| T1 | TODO | Rename definition in primitives crate | Change `NumberOfDownloadsBTreeMap` to `NumberOfDownloadsPerInfoHash` in `packages/primitives/src/lib.rs` | -| T2 | TODO | Update core domain references | Update imports/usages in `tracker-core`, `swarm-coordination-registry`, etc. | -| T3 | TODO | Update benchmarking references | Update imports/usages in `torrent-repository-benchmarking` crate and tests | -| T4 | TODO | Update documentation | Update the 4 doc files referencing the old name | -| T5 | TODO | Run full verification | `linter all`, `cargo test --workspace`, pre-commit checks | +| T1 | DONE | Rename definition in primitives crate | Change `NumberOfDownloadsBTreeMap` to `NumberOfDownloadsPerInfoHash` in `packages/primitives/src/lib.rs` | +| T2 | DONE | Update core domain references | Update imports/usages in `tracker-core`, `swarm-coordination-registry`, etc. | +| T3 | DONE | Update benchmarking references | Update imports/usages in `torrent-repository-benchmarking` crate and tests | +| T4 | DONE | Update documentation | Update the 4 doc files referencing the old name | +| T5 | DONE | Run full verification | `linter all`, `cargo test --workspace`, pre-commit checks | ## Progress Tracking @@ -93,8 +93,8 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`. - [ ] Spec reviewed and approved by user/maintainer - [ ] GitHub issue created and issue number added to this spec - [ ] (Optional, recommended for complex issues) Spec-only PR merged into `develop` before implementation -- [ ] Implementation completed -- [ ] Automatic verification completed (`linter all`, relevant tests, and any pre-push checks) +- [x] Implementation completed +- [x] Automatic verification completed (`linter all`, relevant tests, and any pre-push checks) - [ ] Manual verification scenarios executed and recorded (status + evidence) - [ ] Acceptance criteria reviewed after implementation and updated with evidence - [ ] Reviewer validated acceptance criteria and updated checkboxes @@ -104,6 +104,7 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`. ### Progress Log - 2026-06-30 12:00 UTC - Copilot - Spec draft created +- 2026-07-13 08:30 UTC - Copilot - Implementation completed, PR #1972 opened ## Acceptance Criteria @@ -127,20 +128,20 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`. Status values: `TODO`, `IN_PROGRESS`, `DONE`, `FAILED`, `BLOCKED`. -| ID | Scenario | Command/Steps | Expected Result | Status | Evidence | -| --- | --------------------------- | ----------------------------------------------------------------------- | ------------------------------------------ | ------ | ---------------------------- | -| M1 | Build succeeds after rename | `cargo build --workspace` | Zero errors, no warnings related to rename | TODO | {log/output/screenshot/path} | -| M2 | grep confirms no old name | `grep -r "NumberOfDownloadsBTreeMap" --include="*.rs" --include="*.md"` | No matches found | TODO | {log/output/screenshot/path} | +| ID | Scenario | Command/Steps | Expected Result | Status | Evidence | +| --- | --------------------------- | ----------------------------------------------------------------------- | ------------------------------------------ | ------ | ---------------------------------------------------------------------------------------------- | +| M1 | Build succeeds after rename | `cargo build --workspace` | Zero errors, no warnings related to rename | DONE | Build output shows `Finished` with no errors | +| M2 | grep confirms no old name | `grep -r "NumberOfDownloadsBTreeMap" --include="*.rs" --include="*.md"` | No matches found in code; only spec itself | DONE | Only the issue spec references the old name (describing the rename), no code references remain | ### Acceptance Verification -| AC ID | Status (`TODO`/`DONE`) | Evidence | -| ----- | ---------------------- | ------------------ | -| AC1 | TODO | {test/log/PR link} | -| AC2 | TODO | {test/log/PR link} | -| AC3 | TODO | {test/log/PR link} | -| AC4 | TODO | {test/log/PR link} | -| AC5 | TODO | {test/log/PR link} | +| AC ID | Status (`TODO`/`DONE`) | Evidence | +| ----- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| AC1 | DONE | grep confirms no `.rs` files contain `NumberOfDownloadsBTreeMap`. The only `.md` file with the old name is this spec itself, which intentionally references it to describe the rename | +| AC2 | DONE | `NumberOfDownloadsPerInfoHash` is the sole name used across all 23 modified files | +| AC3 | DONE | `cargo test --tests --workspace --all-targets --all-features` — all tests pass (0 failures) | +| AC4 | DONE | `linter all` — markdown, yaml, toml, cspell, rustfmt, shellcheck all pass. Clippy failure is pre-existing in `http_health_check` (unrelated to rename) | +| AC5 | DONE | Pre-commit checks running successfully (build + doc-tests + unit tests pass) | ## Risks and Trade-offs diff --git a/packages/primitives/src/lib.rs b/packages/primitives/src/lib.rs index bbf139d5c..78a084dde 100644 --- a/packages/primitives/src/lib.rs +++ b/packages/primitives/src/lib.rs @@ -68,4 +68,4 @@ pub mod service_binding { } pub type NumberOfDownloads = u32; -pub type NumberOfDownloadsBTreeMap = BTreeMap; +pub type NumberOfDownloadsPerInfoHash = BTreeMap; diff --git a/packages/swarm-coordination-registry/src/swarm/registry.rs b/packages/swarm-coordination-registry/src/swarm/registry.rs index 355d5889b..cbac4b826 100644 --- a/packages/swarm-coordination-registry/src/swarm/registry.rs +++ b/packages/swarm-coordination-registry/src/swarm/registry.rs @@ -7,7 +7,7 @@ use torrust_clock::conv::convert_from_timestamp_to_datetime_utc; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer}; use crate::CoordinatorHandle; use crate::event::Event; @@ -355,7 +355,7 @@ impl Registry { /// This method takes a set of persisted torrent entries (e.g., from a /// database) and imports them into the in-memory repository for immediate /// access. - pub fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) -> u64 { + pub fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) -> u64 { tracing::info!("Importing persisted info about torrents ..."); let mut torrents_imported = 0; @@ -1273,7 +1273,7 @@ mod tests { use std::sync::Arc; - use torrust_tracker_primitives::NumberOfDownloadsBTreeMap; + use torrust_tracker_primitives::NumberOfDownloadsPerInfoHash; use crate::swarm::registry::Registry; use crate::tests::{leecher, sample_info_hash}; @@ -1284,7 +1284,7 @@ mod tests { let infohash = sample_info_hash(); - let mut persistent_torrents = NumberOfDownloadsBTreeMap::default(); + let mut persistent_torrents = NumberOfDownloadsPerInfoHash::default(); persistent_torrents.insert(infohash, 1); @@ -1304,7 +1304,7 @@ mod tests { let infohash = sample_info_hash(); - let mut persistent_torrents = NumberOfDownloadsBTreeMap::default(); + let mut persistent_torrents = NumberOfDownloadsPerInfoHash::default(); persistent_torrents.insert(infohash, 1); persistent_torrents.insert(infohash, 2); @@ -1329,7 +1329,7 @@ mod tests { // Try to import the torrent entry let new_number_of_downloads = initial_number_of_downloads + 1; - let mut persistent_torrents = NumberOfDownloadsBTreeMap::default(); + let mut persistent_torrents = NumberOfDownloadsPerInfoHash::default(); persistent_torrents.insert(infohash, new_number_of_downloads); swarms.import_persistent(&persistent_torrents); diff --git a/packages/torrent-repository-benchmarking/src/repository/dash_map_mutex_std.rs b/packages/torrent-repository-benchmarking/src/repository/dash_map_mutex_std.rs index 9c485eecb..6c273d343 100644 --- a/packages/torrent-repository-benchmarking/src/repository/dash_map_mutex_std.rs +++ b/packages/torrent-repository-benchmarking/src/repository/dash_map_mutex_std.rs @@ -5,7 +5,7 @@ use torrust_clock::DurationSinceUnixEpoch; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer}; use super::Repository; use crate::entry::peer_list::PeerList; @@ -76,7 +76,7 @@ where } } - fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) { + fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) { for (info_hash, completed) in persistent_torrents { if self.torrents.contains_key(info_hash) { continue; diff --git a/packages/torrent-repository-benchmarking/src/repository/mod.rs b/packages/torrent-repository-benchmarking/src/repository/mod.rs index 77ba175f0..5fe6e4436 100644 --- a/packages/torrent-repository-benchmarking/src/repository/mod.rs +++ b/packages/torrent-repository-benchmarking/src/repository/mod.rs @@ -2,7 +2,7 @@ use torrust_clock::DurationSinceUnixEpoch; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer}; pub mod dash_map_mutex_std; pub mod rw_lock_std; @@ -19,7 +19,7 @@ pub trait Repository: Debug + Default + Sized + 'static { fn get(&self, key: &InfoHash) -> Option; fn get_metrics(&self) -> AggregateActiveSwarmMetadata; fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, T)>; - fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap); + fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash); fn remove(&self, key: &InfoHash) -> Option; fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch); fn remove_peerless_torrents(&self, policy: &TrackerPolicy); @@ -32,7 +32,10 @@ pub trait RepositoryAsync: Debug + Default + Sized + 'static { fn get(&self, key: &InfoHash) -> impl std::future::Future> + Send; fn get_metrics(&self) -> impl std::future::Future + Send; fn get_paginated(&self, pagination: Option<&Pagination>) -> impl std::future::Future> + Send; - fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) -> impl std::future::Future + Send; + fn import_persistent( + &self, + persistent_torrents: &NumberOfDownloadsPerInfoHash, + ) -> impl std::future::Future + Send; fn remove(&self, key: &InfoHash) -> impl std::future::Future> + Send; fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch) -> impl std::future::Future + Send; fn remove_peerless_torrents(&self, policy: &TrackerPolicy) -> impl std::future::Future + Send; diff --git a/packages/torrent-repository-benchmarking/src/repository/rw_lock_std.rs b/packages/torrent-repository-benchmarking/src/repository/rw_lock_std.rs index c3ebc0293..f648413ee 100644 --- a/packages/torrent-repository-benchmarking/src/repository/rw_lock_std.rs +++ b/packages/torrent-repository-benchmarking/src/repository/rw_lock_std.rs @@ -2,7 +2,7 @@ use torrust_clock::DurationSinceUnixEpoch; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer}; use super::Repository; use crate::entry::Entry; @@ -90,7 +90,7 @@ where } } - fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) { + fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) { let mut torrents = self.get_torrents_mut(); for (info_hash, downloaded) in persistent_torrents { diff --git a/packages/torrent-repository-benchmarking/src/repository/rw_lock_std_mutex_std.rs b/packages/torrent-repository-benchmarking/src/repository/rw_lock_std_mutex_std.rs index d5cde31ea..4579f8744 100644 --- a/packages/torrent-repository-benchmarking/src/repository/rw_lock_std_mutex_std.rs +++ b/packages/torrent-repository-benchmarking/src/repository/rw_lock_std_mutex_std.rs @@ -4,7 +4,7 @@ use torrust_clock::DurationSinceUnixEpoch; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer}; use super::Repository; use crate::entry::peer_list::PeerList; @@ -87,7 +87,7 @@ where } } - fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) { + fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) { let mut torrents = self.get_torrents_mut(); for (info_hash, completed) in persistent_torrents { diff --git a/packages/torrent-repository-benchmarking/src/repository/rw_lock_std_mutex_tokio.rs b/packages/torrent-repository-benchmarking/src/repository/rw_lock_std_mutex_tokio.rs index 2ef40ea9c..77bfdf561 100644 --- a/packages/torrent-repository-benchmarking/src/repository/rw_lock_std_mutex_tokio.rs +++ b/packages/torrent-repository-benchmarking/src/repository/rw_lock_std_mutex_tokio.rs @@ -8,7 +8,7 @@ use torrust_clock::DurationSinceUnixEpoch; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer}; use super::RepositoryAsync; use crate::entry::peer_list::PeerList; @@ -100,7 +100,7 @@ where metrics } - fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) -> impl Future + Send { + fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) -> impl Future + Send { let mut db = self.get_torrents_mut(); for (info_hash, completed) in persistent_torrents { diff --git a/packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio.rs b/packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio.rs index f6723366f..a44bdcb6d 100644 --- a/packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio.rs +++ b/packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio.rs @@ -2,7 +2,7 @@ use torrust_clock::DurationSinceUnixEpoch; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer}; use super::RepositoryAsync; use crate::entry::Entry; @@ -97,7 +97,7 @@ where metrics } - async fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) { + async fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) { let mut torrents = self.get_torrents_mut().await; for (info_hash, completed) in persistent_torrents { diff --git a/packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio_mutex_std.rs b/packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio_mutex_std.rs index fed5bb716..599f1f285 100644 --- a/packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio_mutex_std.rs +++ b/packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio_mutex_std.rs @@ -4,7 +4,7 @@ use torrust_clock::DurationSinceUnixEpoch; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer}; use super::RepositoryAsync; use crate::entry::peer_list::PeerList; @@ -92,7 +92,7 @@ where metrics } - async fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) { + async fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) { let mut torrents = self.get_torrents_mut().await; for (info_hash, completed) in persistent_torrents { diff --git a/packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio_mutex_tokio.rs b/packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio_mutex_tokio.rs index 630c828b9..a9061a67b 100644 --- a/packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio_mutex_tokio.rs +++ b/packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio_mutex_tokio.rs @@ -4,7 +4,7 @@ use torrust_clock::DurationSinceUnixEpoch; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer}; use super::RepositoryAsync; use crate::entry::peer_list::PeerList; @@ -95,7 +95,7 @@ where metrics } - async fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) { + async fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) { let mut db = self.get_torrents_mut().await; for (info_hash, completed) in persistent_torrents { diff --git a/packages/torrent-repository-benchmarking/src/repository/skip_map_mutex_std.rs b/packages/torrent-repository-benchmarking/src/repository/skip_map_mutex_std.rs index ca0b2ade3..978ef3d89 100644 --- a/packages/torrent-repository-benchmarking/src/repository/skip_map_mutex_std.rs +++ b/packages/torrent-repository-benchmarking/src/repository/skip_map_mutex_std.rs @@ -5,7 +5,7 @@ use torrust_clock::DurationSinceUnixEpoch; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer}; use super::Repository; use crate::entry::peer_list::PeerList; @@ -100,7 +100,7 @@ where } } - fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) { + fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) { for (info_hash, completed) in persistent_torrents { if self.torrents.contains_key(info_hash) { continue; @@ -193,7 +193,7 @@ where } } - fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) { + fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) { for (info_hash, completed) in persistent_torrents { if self.torrents.contains_key(info_hash) { continue; @@ -286,7 +286,7 @@ where } } - fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) { + fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) { for (info_hash, completed) in persistent_torrents { if self.torrents.contains_key(info_hash) { continue; diff --git a/packages/torrent-repository-benchmarking/tests/common/repo.rs b/packages/torrent-repository-benchmarking/tests/common/repo.rs index ab07dae17..96e6e4247 100644 --- a/packages/torrent-repository-benchmarking/tests/common/repo.rs +++ b/packages/torrent-repository-benchmarking/tests/common/repo.rs @@ -2,7 +2,7 @@ use torrust_clock::DurationSinceUnixEpoch; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer}; use torrust_tracker_torrent_repository_benchmarking::repository::{Repository as _, RepositoryAsync as _}; use torrust_tracker_torrent_repository_benchmarking::{ EntrySingle, TorrentsDashMapMutexStd, TorrentsRwLockStd, TorrentsRwLockStdMutexStd, TorrentsRwLockStdMutexTokio, @@ -144,7 +144,7 @@ impl Repo { } } - pub(crate) async fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) { + pub(crate) async fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) { match self { Self::RwLockStd(repo) => repo.import_persistent(persistent_torrents), Self::RwLockStdMutexStd(repo) => repo.import_persistent(persistent_torrents), diff --git a/packages/torrent-repository-benchmarking/tests/repository/mod.rs b/packages/torrent-repository-benchmarking/tests/repository/mod.rs index 369d83460..a8469413a 100644 --- a/packages/torrent-repository-benchmarking/tests/repository/mod.rs +++ b/packages/torrent-repository-benchmarking/tests/repository/mod.rs @@ -5,7 +5,7 @@ use rstest::{fixture, rstest}; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; -use torrust_tracker_primitives::{AnnounceEvent, NumberOfBytes, NumberOfDownloadsBTreeMap, TrackerPolicy}; +use torrust_tracker_primitives::{AnnounceEvent, NumberOfBytes, NumberOfDownloadsPerInfoHash, TrackerPolicy}; use torrust_tracker_torrent_repository_benchmarking::EntrySingle; use torrust_tracker_torrent_repository_benchmarking::entry::Entry as _; use torrust_tracker_torrent_repository_benchmarking::repository::dash_map_mutex_std::XacrimonDashMap; @@ -165,12 +165,12 @@ fn many_hashed_in_order() -> Entries { } #[fixture] -fn persistent_empty() -> NumberOfDownloadsBTreeMap { - NumberOfDownloadsBTreeMap::default() +fn persistent_empty() -> NumberOfDownloadsPerInfoHash { + NumberOfDownloadsPerInfoHash::default() } #[fixture] -fn persistent_single() -> NumberOfDownloadsBTreeMap { +fn persistent_single() -> NumberOfDownloadsPerInfoHash { let hash = &mut DefaultHasher::default(); hash.write_u8(1); @@ -180,7 +180,7 @@ fn persistent_single() -> NumberOfDownloadsBTreeMap { } #[fixture] -fn persistent_three() -> NumberOfDownloadsBTreeMap { +fn persistent_three() -> NumberOfDownloadsPerInfoHash { let hash = &mut DefaultHasher::default(); hash.write_u8(1); @@ -441,7 +441,7 @@ async fn it_should_import_persistent_torrents( )] repo: Repo, #[case] entries: Entries, - #[values(persistent_empty(), persistent_single(), persistent_three())] persistent_torrents: NumberOfDownloadsBTreeMap, + #[values(persistent_empty(), persistent_single(), persistent_three())] persistent_torrents: NumberOfDownloadsPerInfoHash, ) { make(&repo, &entries).await; diff --git a/packages/tracker-core/src/databases/driver/mysql/torrent_metrics_store.rs b/packages/tracker-core/src/databases/driver/mysql/torrent_metrics_store.rs index 1a7935edc..af8ba4386 100644 --- a/packages/tracker-core/src/databases/driver/mysql/torrent_metrics_store.rs +++ b/packages/tracker-core/src/databases/driver/mysql/torrent_metrics_store.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use ::sqlx::Row; use async_trait::async_trait; use torrust_info_hash::InfoHash; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash}; use super::{DRIVER, Mysql}; use crate::databases::TorrentMetricsStore; @@ -12,7 +12,7 @@ use crate::databases::error::Error; #[async_trait] impl TorrentMetricsStore for Mysql { - async fn load_all_torrents_downloads(&self) -> Result { + async fn load_all_torrents_downloads(&self) -> Result { let rows = ::sqlx::query("SELECT info_hash, completed FROM torrents") .fetch_all(&self.pool) .await diff --git a/packages/tracker-core/src/databases/driver/postgres/torrent_metrics_store.rs b/packages/tracker-core/src/databases/driver/postgres/torrent_metrics_store.rs index 8a83d060d..418b02b11 100644 --- a/packages/tracker-core/src/databases/driver/postgres/torrent_metrics_store.rs +++ b/packages/tracker-core/src/databases/driver/postgres/torrent_metrics_store.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use ::sqlx::Row; use async_trait::async_trait; use torrust_info_hash::InfoHash; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash}; use super::{DRIVER, Postgres}; use crate::databases::TorrentMetricsStore; @@ -12,7 +12,7 @@ use crate::databases::error::Error; #[async_trait] impl TorrentMetricsStore for Postgres { - async fn load_all_torrents_downloads(&self) -> Result { + async fn load_all_torrents_downloads(&self) -> Result { let rows = ::sqlx::query("SELECT info_hash, completed FROM torrents") .fetch_all(&self.pool) .await diff --git a/packages/tracker-core/src/databases/driver/sqlite/torrent_metrics_store.rs b/packages/tracker-core/src/databases/driver/sqlite/torrent_metrics_store.rs index b975aea25..1f6c2114c 100644 --- a/packages/tracker-core/src/databases/driver/sqlite/torrent_metrics_store.rs +++ b/packages/tracker-core/src/databases/driver/sqlite/torrent_metrics_store.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use ::sqlx::Row; use async_trait::async_trait; use torrust_info_hash::InfoHash; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash}; use super::{DRIVER, Sqlite}; use crate::databases::TorrentMetricsStore; @@ -12,7 +12,7 @@ use crate::databases::error::Error; #[async_trait] impl TorrentMetricsStore for Sqlite { - async fn load_all_torrents_downloads(&self) -> Result { + async fn load_all_torrents_downloads(&self) -> Result { let rows = ::sqlx::query("SELECT info_hash, completed FROM torrents") .fetch_all(&self.pool) .await diff --git a/packages/tracker-core/src/databases/traits/torrent_metrics.rs b/packages/tracker-core/src/databases/traits/torrent_metrics.rs index 847636f50..bc14c41b5 100644 --- a/packages/tracker-core/src/databases/traits/torrent_metrics.rs +++ b/packages/tracker-core/src/databases/traits/torrent_metrics.rs @@ -7,7 +7,7 @@ use async_trait::async_trait; use mockall::automock; use torrust_info_hash::InfoHash; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash}; use super::super::error::Error; @@ -26,7 +26,7 @@ pub trait TorrentMetricsStore: Sync + Send { /// # Errors /// /// Returns an [`Error`] if the metrics cannot be loaded. - async fn load_all_torrents_downloads(&self) -> Result; + async fn load_all_torrents_downloads(&self) -> Result; /// Loads torrent metrics data from the database for one torrent. /// diff --git a/packages/tracker-core/src/statistics/persisted/downloads.rs b/packages/tracker-core/src/statistics/persisted/downloads.rs index c30c190f3..09c3de4f8 100644 --- a/packages/tracker-core/src/statistics/persisted/downloads.rs +++ b/packages/tracker-core/src/statistics/persisted/downloads.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use torrust_info_hash::InfoHash; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash}; use crate::databases::TorrentMetricsStore; use crate::databases::error::Error; @@ -76,7 +76,7 @@ impl DatabaseDownloadsMetricRepository { /// # Errors /// /// Returns an [`Error`] if the underlying database query fails. - pub(crate) async fn load_all_torrents_downloads(&self) -> Result { + pub(crate) async fn load_all_torrents_downloads(&self) -> Result { self.database.load_all_torrents_downloads().await } @@ -140,7 +140,7 @@ impl DatabaseDownloadsMetricRepository { #[cfg(test)] mod tests { - use torrust_tracker_primitives::NumberOfDownloadsBTreeMap; + use torrust_tracker_primitives::NumberOfDownloadsPerInfoHash; use super::DatabaseDownloadsMetricRepository; use crate::databases::setup::initialize_database; @@ -190,7 +190,7 @@ mod tests { let torrents = repository.load_all_torrents_downloads().await.unwrap(); - let mut expected_torrents = NumberOfDownloadsBTreeMap::new(); + let mut expected_torrents = NumberOfDownloadsPerInfoHash::new(); expected_torrents.insert(infohash_one, 1); expected_torrents.insert(infohash_two, 2); diff --git a/packages/tracker-core/src/torrent/repository/in_memory.rs b/packages/tracker-core/src/torrent/repository/in_memory.rs index 8cb29a930..0b2903b4a 100644 --- a/packages/tracker-core/src/torrent/repository/in_memory.rs +++ b/packages/tracker-core/src/torrent/repository/in_memory.rs @@ -5,7 +5,7 @@ use torrust_clock::DurationSinceUnixEpoch; use torrust_info_hash::InfoHash; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; -use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer}; +use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer}; use torrust_tracker_swarm_coordination_registry::{CoordinatorHandle, Registry}; /// In-memory repository for torrent entries. @@ -262,7 +262,7 @@ impl InMemoryTorrentRepository { /// # Arguments /// /// * `persistent_torrents` - A reference to the persisted torrent data. - pub fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) { + pub fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) { self.swarms.import_persistent(persistent_torrents); }