Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/issues/closed/1713-1525-04-split-persistence-traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub trait SchemaMigrator: Sync + Send {
```rust
#[automock]
pub trait TorrentMetricsStore: Sync + Send {
fn load_all_torrents_downloads(&self) -> Result<NumberOfDownloadsBTreeMap, Error>;
fn load_all_torrents_downloads(&self) -> Result<NumberOfDownloadsPerInfoHash, Error>;
fn load_torrent_downloads(&self, info_hash: &InfoHash) -> Result<Option<NumberOfDownloads>, Error>;
fn save_torrent_downloads(&self, info_hash: &InfoHash, downloaded: NumberOfDownloads) -> Result<(), Error>;
fn increase_downloads_for_torrent(&self, info_hash: &InfoHash) -> Result<(), Error>;
Expand Down Expand Up @@ -224,7 +224,7 @@ impl SchemaMigrator for Sqlite {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ pub mod service_binding {
}

pub type NumberOfDownloads = u32;
pub type NumberOfDownloadsBTreeMap = BTreeMap<InfoHash, NumberOfDownloads>;
pub type NumberOfDownloadsPerInfoHash = BTreeMap<InfoHash, NumberOfDownloads>;
12 changes: 6 additions & 6 deletions packages/swarm-coordination-registry/src/swarm/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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};
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +19,7 @@ pub trait Repository<T>: Debug + Default + Sized + 'static {
fn get(&self, key: &InfoHash) -> Option<T>;
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<T>;
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch);
fn remove_peerless_torrents(&self, policy: &TrackerPolicy);
Expand All @@ -32,7 +32,10 @@ pub trait RepositoryAsync<T>: Debug + Default + Sized + 'static {
fn get(&self, key: &InfoHash) -> impl std::future::Future<Output = Option<T>> + Send;
fn get_metrics(&self) -> impl std::future::Future<Output = AggregateActiveSwarmMetadata> + Send;
fn get_paginated(&self, pagination: Option<&Pagination>) -> impl std::future::Future<Output = Vec<(InfoHash, T)>> + Send;
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) -> impl std::future::Future<Output = ()> + Send;
fn import_persistent(
&self,
persistent_torrents: &NumberOfDownloadsPerInfoHash,
) -> impl std::future::Future<Output = ()> + Send;
fn remove(&self, key: &InfoHash) -> impl std::future::Future<Output = Option<T>> + Send;
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch) -> impl std::future::Future<Output = ()> + Send;
fn remove_peerless_torrents(&self, policy: &TrackerPolicy) -> impl std::future::Future<Output = ()> + Send;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,7 +100,7 @@ where
metrics
}

fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) -> impl Future<Output = ()> + Send {
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsPerInfoHash) -> impl Future<Output = ()> + Send {
let mut db = self.get_torrents_mut();

for (info_hash, completed) in persistent_torrents {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Loading
Loading