-
Notifications
You must be signed in to change notification settings - Fork 48
Overhaul stats: Improve torrent-repository package before adding events (part 1) #1497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
josecelano
merged 20 commits into
torrust:develop
from
josecelano:1495-overhaul-stats-improve-torrent-repository-package-before-adding-events
May 6, 2025
Merged
Overhaul stats: Improve torrent-repository package before adding events (part 1) #1497
josecelano
merged 20 commits into
torrust:develop
from
josecelano:1495-overhaul-stats-improve-torrent-repository-package-before-adding-events
May 6, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1497 +/- ##
===========================================
+ Coverage 84.83% 85.06% +0.23%
===========================================
Files 259 258 -1
Lines 20287 20546 +259
Branches 20287 20546 +259
===========================================
+ Hits 17210 17477 +267
+ Misses 2788 2781 -7
+ Partials 289 288 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This change prevents duplicate peers with the same address but different IDs, ensuring more accurate peer tracking.
- Moved responsability for keeping metadata to the Swarm type. - Number of seeder and leechers is now calculated when the Swarm changes not on-demand. We avoid iterating over the peers to get the number of seeders and leechers. - The number of downloads is also calculate now in the Swarm. It will be removed from the TrackedTorrent.
…ad of from TrackedTorrent
Changed from:
```
/// Returns true if the torrents meets the retention policy, meaning that
/// it should be kept in the tracker.
pub fn meets_retaining_policy(&self, policy: &TrackerPolicy) -> bool {
if policy.persistent_torrent_completed_stat && self.metadata().downloaded > 0 {
return true;
}
if policy.remove_peerless_torrents && self.is_empty() {
return false;
}
true
}
```
To:
```
pub fn meets_retaining_policy(&self, policy: &TrackerPolicy) -> bool {
!(policy.remove_peerless_torrents && self.is_empty())
}
```
I think the first condition was introduced to avoid loosing the number of
downloads we¡hen the torrent is removed becuase there are no peers.
Now, we load that number from database when the torrent is added again
after removing it from the tracker.
Member
Author
|
ACK 728de22 |
5 tasks
josecelano
added a commit
that referenced
this pull request
May 7, 2025
…e adding events (part 2) 4d91738 refactor: [#1495] renamings in torrent-repository pkg (Jose Celano) 5b3142f refactor: [#1495] refactor Swarms::upsert_peer (Jose Celano) 5c2c1e0 feat: [#1495] add len and is_empty methods to Swarms type (Jose Celano) 31f1fbf refactgor: [#1495] make field private (Jose Celano) 6d50fa0 refactor: [#1495] remove panics from Swarms type (Jose Celano) 5413e59 refactor: [#1495] renamings to follow latest changes in torrent-repository pkg (Jose Celano) 6f5cb27 refactor: [#1495] remove test for SwarmHandle (Jose Celano) Pull request description: Improve `torrent-repository` package before adding events. This is a continuation of [tracker/issues/1495](#1497). #### Refactoring `TorrentRepository` - [x] Return errors instead of panicking in `Swarms` type. - [x] Make field `swarms` private. - [x] Add `len` and `is_empty` methods. - [x] Refactor `upsert_peer`. - [x] Renamings to follow the latest changes in type names. ACKs for top commit: josecelano: ACK 4d91738 Tree-SHA512: 4ee9be1c21a62148d0d4fa0a9263c54312239fc98e2540d7583689a50126883ba563b5c676a606196c5696b14a4452a14061159b3ac2c69dd02c493c7930ceaf
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Partially implements #1495
Improve
torrent-repositorypackage before adding events.Sutasks
Refactoring
PeerListPeerListtoSwarm.SocketAddras key for peers inSwarminstead of thePeerId.TrackerTorrenttoSwarmRefactoring
TrackedTorrent(it was removed)downloadedfield fromTrackedTorrent. The logic can be moved toSwarm.meets_retaining_policymethod behavior. I don't know why peerless torrents are kept when persisted stats (downloadedfield) are enabled (only if the torrent has been downloaded at least once).It was removed because after the refactorings, it became just a wrapper over
Swarm.Refactoring
TorrentRepositoryTo be implemented in a new PR.
New state
There are only two primary types:
Swarm: a collection of peers. Peers are members of the swarm.Swarms: a collection of swarms.