Skip to content

Commit fd88bb6

Browse files
committed
Merge torrust#1972: refactor(primitives): rename NumberOfDownloadsBTreeMap to NumberOfDownloadsPerInfoHash
9fd2861 docs(spec): reword AC1 evidence to clarify grep result scope (Jose Celano) e0fbe78 refactor(primitives): rename NumberOfDownloadsBTreeMap to NumberOfDownloadsPerInfoHash (Jose Celano) Pull request description: ## What Renamed the type alias `NumberOfDownloadsBTreeMap` to `NumberOfDownloadsPerInfoHash` across the entire workspace (23 source files + docs). ## Why The old name `NumberOfDownloadsBTreeMap` leaks the implementation detail (`BTreeMap`). The new name expresses **what** the type represents ("downloads per info-hash") rather than **how** it's stored, matching the convention of its sibling `NumberOfDownloads`. Closes torrust#1964 ## How - Changed the definition in `packages/primitives/src/lib.rs` - Updated all imports and usages in `tracker-core`, `swarm-coordination-registry`, `torrent-repository-benchmarking`, and their tests - Updated 4 documentation files referencing the old name - Verified: `cargo build --workspace` succeeds, all unit tests pass, `linter all` passes (clippy failure is pre-existing in `http_health_check`, unrelated) ## Verification - [x] Build: `cargo build --workspace` — success - [x] Tests: `cargo test --workspace --all-targets --all-features` — 262 tests pass, 0 failures - [x] Linting: markdown, yaml, toml, cspell, rustfmt, shellcheck all pass - [x] grep: No `.rs` or `.md` files contain the old name (except the issue spec itself) - [x] Pre-commit checks: all pass ACKs for top commit: josecelano: ACK 9fd2861 Tree-SHA512: 2057d340b00f2ca202e72fcd9dc7526b04ac0e8f45ebca8a69606beadb18b0fc1d2c0bd923a2632c6ef6a460040cfc2502315f601276619a18ef6fa32c06277c
2 parents 9411353 + 9fd2861 commit fd88bb6

24 files changed

Lines changed: 80 additions & 76 deletions

docs/issues/closed/1713-1525-04-split-persistence-traits.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub trait SchemaMigrator: Sync + Send {
138138
```rust
139139
#[automock]
140140
pub trait TorrentMetricsStore: Sync + Send {
141-
fn load_all_torrents_downloads(&self) -> Result<NumberOfDownloadsBTreeMap, Error>;
141+
fn load_all_torrents_downloads(&self) -> Result<NumberOfDownloadsPerInfoHash, Error>;
142142
fn load_torrent_downloads(&self, info_hash: &InfoHash) -> Result<Option<NumberOfDownloads>, Error>;
143143
fn save_torrent_downloads(&self, info_hash: &InfoHash, downloaded: NumberOfDownloads) -> Result<(), Error>;
144144
fn increase_downloads_for_torrent(&self, info_hash: &InfoHash) -> Result<(), Error>;
@@ -224,7 +224,7 @@ impl SchemaMigrator for Sqlite {
224224
}
225225

226226
impl TorrentMetricsStore for Sqlite {
227-
fn load_all_torrents_downloads(&self) -> Result<NumberOfDownloadsBTreeMap, Error> { ... }
227+
fn load_all_torrents_downloads(&self) -> Result<NumberOfDownloadsPerInfoHash, Error> { ... }
228228
// ... remaining 6 methods
229229
}
230230

docs/issues/open/1669-overhaul-packages/workspace-coupling-report-2026-05-19.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Workspace deps: 9
242242
- `torrust_tracker_primitives::AnnouncePolicy`
243243
- `torrust_tracker_primitives::NumberOfBytes`
244244
- `torrust_tracker_primitives::NumberOfDownloads`
245-
- `torrust_tracker_primitives::NumberOfDownloadsBTreeMap`
245+
- `torrust_tracker_primitives::NumberOfDownloadsPerInfoHash`
246246
- `torrust_tracker_primitives::PeerId`
247247
- `torrust_tracker_primitives::ScrapeData`
248248
- `torrust_tracker_primitives::pagination::Pagination`
@@ -898,7 +898,7 @@ Workspace deps: 6
898898
- `torrust_tracker_primitives::AnnounceEvent::Completed`
899899
- `torrust_tracker_primitives::AnnounceEvent::Started`
900900
- `torrust_tracker_primitives::NumberOfBytes`
901-
- `torrust_tracker_primitives::NumberOfDownloadsBTreeMap`
901+
- `torrust_tracker_primitives::NumberOfDownloadsPerInfoHash`
902902
- `torrust_tracker_primitives::PeerId`
903903
- `torrust_tracker_primitives::pagination::Pagination`
904904
- `torrust_tracker_primitives::peer`

docs/issues/open/1669-overhaul-packages/workspace-coupling-report-2026-06-10.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ Workspace deps: 5
430430
- `torrust_tracker_primitives::AnnouncePolicy`
431431
- `torrust_tracker_primitives::NumberOfBytes`
432432
- `torrust_tracker_primitives::NumberOfDownloads`
433-
- `torrust_tracker_primitives::NumberOfDownloadsBTreeMap`
433+
- `torrust_tracker_primitives::NumberOfDownloadsPerInfoHash`
434434
- `torrust_tracker_primitives::PeerId`
435435
- `torrust_tracker_primitives::PrivateMode`
436436
- `torrust_tracker_primitives::ScrapeData`
@@ -615,7 +615,7 @@ Workspace deps: 2
615615
- `torrust_tracker_primitives::AnnounceEvent::Completed`
616616
- `torrust_tracker_primitives::AnnounceEvent::Started`
617617
- `torrust_tracker_primitives::NumberOfBytes`
618-
- `torrust_tracker_primitives::NumberOfDownloadsBTreeMap`
618+
- `torrust_tracker_primitives::NumberOfDownloadsPerInfoHash`
619619
- `torrust_tracker_primitives::PeerId`
620620
- `torrust_tracker_primitives::TrackerPolicy`
621621
- `torrust_tracker_primitives::pagination::Pagination`

docs/issues/open/1669-overhaul-packages/workspace-coupling-report-proposed-merge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ _`http` feature_:
248248
- `torrust_tracker_primitives::AnnouncePolicy`
249249
- `torrust_tracker_primitives::NumberOfBytes`
250250
- `torrust_tracker_primitives::NumberOfDownloads`
251-
- `torrust_tracker_primitives::NumberOfDownloadsBTreeMap`
251+
- `torrust_tracker_primitives::NumberOfDownloadsPerInfoHash`
252252
- `torrust_tracker_primitives::PeerId`
253253
- `torrust_tracker_primitives::ScrapeData`
254254
- `torrust_tracker_primitives::pagination::Pagination`

docs/issues/open/1964-rename-number-of-downloads-btree-map-type-alias.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ priority: p2
66
github-issue: 1964
77
spec-path: docs/issues/open/1964-rename-number-of-downloads-btree-map-type-alias.md
88
branch: "1964-rename-number-of-downloads-btree-map"
9-
related-pr: null
9+
related-pr: "https://github.com/torrust/torrust-tracker/pull/1972"
1010
last-updated-utc: 2026-06-30 12:00
1111
semantic-links:
1212
skill-links:
@@ -79,11 +79,11 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`.
7979

8080
| ID | Status | Task | Notes / Expected Output |
8181
| --- | ------ | ------------------------------------- | -------------------------------------------------------------------------------------------------------- |
82-
| T1 | TODO | Rename definition in primitives crate | Change `NumberOfDownloadsBTreeMap` to `NumberOfDownloadsPerInfoHash` in `packages/primitives/src/lib.rs` |
83-
| T2 | TODO | Update core domain references | Update imports/usages in `tracker-core`, `swarm-coordination-registry`, etc. |
84-
| T3 | TODO | Update benchmarking references | Update imports/usages in `torrent-repository-benchmarking` crate and tests |
85-
| T4 | TODO | Update documentation | Update the 4 doc files referencing the old name |
86-
| T5 | TODO | Run full verification | `linter all`, `cargo test --workspace`, pre-commit checks |
82+
| T1 | DONE | Rename definition in primitives crate | Change `NumberOfDownloadsBTreeMap` to `NumberOfDownloadsPerInfoHash` in `packages/primitives/src/lib.rs` |
83+
| T2 | DONE | Update core domain references | Update imports/usages in `tracker-core`, `swarm-coordination-registry`, etc. |
84+
| T3 | DONE | Update benchmarking references | Update imports/usages in `torrent-repository-benchmarking` crate and tests |
85+
| T4 | DONE | Update documentation | Update the 4 doc files referencing the old name |
86+
| T5 | DONE | Run full verification | `linter all`, `cargo test --workspace`, pre-commit checks |
8787

8888
## Progress Tracking
8989

@@ -93,8 +93,8 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`.
9393
- [ ] Spec reviewed and approved by user/maintainer
9494
- [ ] GitHub issue created and issue number added to this spec
9595
- [ ] (Optional, recommended for complex issues) Spec-only PR merged into `develop` before implementation
96-
- [ ] Implementation completed
97-
- [ ] Automatic verification completed (`linter all`, relevant tests, and any pre-push checks)
96+
- [x] Implementation completed
97+
- [x] Automatic verification completed (`linter all`, relevant tests, and any pre-push checks)
9898
- [ ] Manual verification scenarios executed and recorded (status + evidence)
9999
- [ ] Acceptance criteria reviewed after implementation and updated with evidence
100100
- [ ] Reviewer validated acceptance criteria and updated checkboxes
@@ -104,6 +104,7 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`.
104104
### Progress Log
105105

106106
- 2026-06-30 12:00 UTC - Copilot - Spec draft created
107+
- 2026-07-13 08:30 UTC - Copilot - Implementation completed, PR #1972 opened
107108

108109
## Acceptance Criteria
109110

@@ -127,20 +128,20 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`.
127128

128129
Status values: `TODO`, `IN_PROGRESS`, `DONE`, `FAILED`, `BLOCKED`.
129130

130-
| ID | Scenario | Command/Steps | Expected Result | Status | Evidence |
131-
| --- | --------------------------- | ----------------------------------------------------------------------- | ------------------------------------------ | ------ | ---------------------------- |
132-
| M1 | Build succeeds after rename | `cargo build --workspace` | Zero errors, no warnings related to rename | TODO | {log/output/screenshot/path} |
133-
| M2 | grep confirms no old name | `grep -r "NumberOfDownloadsBTreeMap" --include="*.rs" --include="*.md"` | No matches found | TODO | {log/output/screenshot/path} |
131+
| ID | Scenario | Command/Steps | Expected Result | Status | Evidence |
132+
| --- | --------------------------- | ----------------------------------------------------------------------- | ------------------------------------------ | ------ | ---------------------------------------------------------------------------------------------- |
133+
| M1 | Build succeeds after rename | `cargo build --workspace` | Zero errors, no warnings related to rename | DONE | Build output shows `Finished` with no errors |
134+
| 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 |
134135

135136
### Acceptance Verification
136137

137-
| AC ID | Status (`TODO`/`DONE`) | Evidence |
138-
| ----- | ---------------------- | ------------------ |
139-
| AC1 | TODO | {test/log/PR link} |
140-
| AC2 | TODO | {test/log/PR link} |
141-
| AC3 | TODO | {test/log/PR link} |
142-
| AC4 | TODO | {test/log/PR link} |
143-
| AC5 | TODO | {test/log/PR link} |
138+
| AC ID | Status (`TODO`/`DONE`) | Evidence |
139+
| ----- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
140+
| 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 |
141+
| AC2 | DONE | `NumberOfDownloadsPerInfoHash` is the sole name used across all 23 modified files |
142+
| AC3 | DONE | `cargo test --tests --workspace --all-targets --all-features` — all tests pass (0 failures) |
143+
| AC4 | DONE | `linter all` — markdown, yaml, toml, cspell, rustfmt, shellcheck all pass. Clippy failure is pre-existing in `http_health_check` (unrelated to rename) |
144+
| AC5 | DONE | Pre-commit checks running successfully (build + doc-tests + unit tests pass) |
144145

145146
## Risks and Trade-offs
146147

packages/primitives/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ pub mod service_binding {
6868
}
6969

7070
pub type NumberOfDownloads = u32;
71-
pub type NumberOfDownloadsBTreeMap = BTreeMap<InfoHash, NumberOfDownloads>;
71+
pub type NumberOfDownloadsPerInfoHash = BTreeMap<InfoHash, NumberOfDownloads>;

packages/swarm-coordination-registry/src/swarm/registry.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use torrust_clock::conv::convert_from_timestamp_to_datetime_utc;
77
use torrust_info_hash::InfoHash;
88
use torrust_tracker_primitives::pagination::Pagination;
99
use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata};
10-
use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer};
10+
use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer};
1111

1212
use crate::CoordinatorHandle;
1313
use crate::event::Event;
@@ -355,7 +355,7 @@ impl Registry {
355355
/// This method takes a set of persisted torrent entries (e.g., from a
356356
/// database) and imports them into the in-memory repository for immediate
357357
/// access.
358-
pub fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) -> u64 {
358+
pub fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) -> u64 {
359359
tracing::info!("Importing persisted info about torrents ...");
360360

361361
let mut torrents_imported = 0;
@@ -1273,7 +1273,7 @@ mod tests {
12731273

12741274
use std::sync::Arc;
12751275

1276-
use torrust_tracker_primitives::NumberOfDownloadsBTreeMap;
1276+
use torrust_tracker_primitives::NumberOfDownloadsPerInfoHash;
12771277

12781278
use crate::swarm::registry::Registry;
12791279
use crate::tests::{leecher, sample_info_hash};
@@ -1284,7 +1284,7 @@ mod tests {
12841284

12851285
let infohash = sample_info_hash();
12861286

1287-
let mut persistent_torrents = NumberOfDownloadsBTreeMap::default();
1287+
let mut persistent_torrents = NumberOfDownloadsPerInfoHash::default();
12881288

12891289
persistent_torrents.insert(infohash, 1);
12901290

@@ -1304,7 +1304,7 @@ mod tests {
13041304

13051305
let infohash = sample_info_hash();
13061306

1307-
let mut persistent_torrents = NumberOfDownloadsBTreeMap::default();
1307+
let mut persistent_torrents = NumberOfDownloadsPerInfoHash::default();
13081308

13091309
persistent_torrents.insert(infohash, 1);
13101310
persistent_torrents.insert(infohash, 2);
@@ -1329,7 +1329,7 @@ mod tests {
13291329

13301330
// Try to import the torrent entry
13311331
let new_number_of_downloads = initial_number_of_downloads + 1;
1332-
let mut persistent_torrents = NumberOfDownloadsBTreeMap::default();
1332+
let mut persistent_torrents = NumberOfDownloadsPerInfoHash::default();
13331333
persistent_torrents.insert(infohash, new_number_of_downloads);
13341334
swarms.import_persistent(&persistent_torrents);
13351335

packages/torrent-repository-benchmarking/src/repository/dash_map_mutex_std.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use torrust_clock::DurationSinceUnixEpoch;
55
use torrust_info_hash::InfoHash;
66
use torrust_tracker_primitives::pagination::Pagination;
77
use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata};
8-
use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer};
8+
use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer};
99

1010
use super::Repository;
1111
use crate::entry::peer_list::PeerList;
@@ -76,7 +76,7 @@ where
7676
}
7777
}
7878

79-
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) {
79+
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) {
8080
for (info_hash, completed) in persistent_torrents {
8181
if self.torrents.contains_key(info_hash) {
8282
continue;

packages/torrent-repository-benchmarking/src/repository/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use torrust_clock::DurationSinceUnixEpoch;
22
use torrust_info_hash::InfoHash;
33
use torrust_tracker_primitives::pagination::Pagination;
44
use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata};
5-
use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer};
5+
use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer};
66

77
pub mod dash_map_mutex_std;
88
pub mod rw_lock_std;
@@ -19,7 +19,7 @@ pub trait Repository<T>: Debug + Default + Sized + 'static {
1919
fn get(&self, key: &InfoHash) -> Option<T>;
2020
fn get_metrics(&self) -> AggregateActiveSwarmMetadata;
2121
fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, T)>;
22-
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap);
22+
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash);
2323
fn remove(&self, key: &InfoHash) -> Option<T>;
2424
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch);
2525
fn remove_peerless_torrents(&self, policy: &TrackerPolicy);
@@ -32,7 +32,10 @@ pub trait RepositoryAsync<T>: Debug + Default + Sized + 'static {
3232
fn get(&self, key: &InfoHash) -> impl std::future::Future<Output = Option<T>> + Send;
3333
fn get_metrics(&self) -> impl std::future::Future<Output = AggregateActiveSwarmMetadata> + Send;
3434
fn get_paginated(&self, pagination: Option<&Pagination>) -> impl std::future::Future<Output = Vec<(InfoHash, T)>> + Send;
35-
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) -> impl std::future::Future<Output = ()> + Send;
35+
fn import_persistent(
36+
&self,
37+
persistent_torrents: &NumberOfDownloadsPerInfoHash,
38+
) -> impl std::future::Future<Output = ()> + Send;
3639
fn remove(&self, key: &InfoHash) -> impl std::future::Future<Output = Option<T>> + Send;
3740
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch) -> impl std::future::Future<Output = ()> + Send;
3841
fn remove_peerless_torrents(&self, policy: &TrackerPolicy) -> impl std::future::Future<Output = ()> + Send;

packages/torrent-repository-benchmarking/src/repository/rw_lock_std.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use torrust_clock::DurationSinceUnixEpoch;
22
use torrust_info_hash::InfoHash;
33
use torrust_tracker_primitives::pagination::Pagination;
44
use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata};
5-
use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsBTreeMap, TrackerPolicy, peer};
5+
use torrust_tracker_primitives::{NumberOfDownloads, NumberOfDownloadsPerInfoHash, TrackerPolicy, peer};
66

77
use super::Repository;
88
use crate::entry::Entry;
@@ -90,7 +90,7 @@ where
9090
}
9191
}
9292

93-
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) {
93+
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) {
9494
let mut torrents = self.get_torrents_mut();
9595

9696
for (info_hash, downloaded) in persistent_torrents {

0 commit comments

Comments
 (0)