Skip to content

Commit b3fcdb4

Browse files
committed
refactor: [#1201] remove direct dependency on database from tracker
1 parent bdc3f22 commit b3fcdb4

File tree

13 files changed

+32
-69
lines changed

13 files changed

+32
-69
lines changed

src/bootstrap/app.rs

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ pub fn initialize_app_container(configuration: &Configuration) -> AppContainer {
116116

117117
let tracker = Arc::new(initialize_tracker(
118118
configuration,
119-
&database,
120119
&whitelist_authorization,
121120
&in_memory_torrent_repository,
122121
&db_torrent_repository,

src/core/mod.rs

+2-24
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,6 @@ use torrust_tracker_primitives::peer;
462462
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
463463
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
464464

465-
use crate::core::databases::Database;
466-
467465
/// The domain layer tracker service.
468466
///
469467
/// Its main responsibility is to handle the `announce` and `scrape` requests.
@@ -477,10 +475,6 @@ pub struct Tracker {
477475
/// The tracker configuration.
478476
config: Core,
479477

480-
/// A database driver implementation: [`Sqlite3`](crate::core::databases::sqlite)
481-
/// or [`MySQL`](crate::core::databases::mysql)
482-
database: Arc<Box<dyn Database>>,
483-
484478
/// The service to check is a torrent is whitelisted.
485479
pub whitelist_authorization: Arc<whitelist::authorization::Authorization>,
486480

@@ -544,15 +538,13 @@ impl Tracker {
544538
/// Will return a `databases::error::Error` if unable to connect to database. The `Tracker` is responsible for the persistence.
545539
pub fn new(
546540
config: &Core,
547-
database: &Arc<Box<dyn Database>>,
548541
whitelist_authorization: &Arc<whitelist::authorization::Authorization>,
549542
in_memory_torrent_repository: &Arc<InMemoryTorrentRepository>,
550543
db_torrent_repository: &Arc<DatabasePersistentTorrentRepository>,
551544
torrents_manager: &Arc<TorrentsManager>,
552545
) -> Result<Tracker, databases::error::Error> {
553546
Ok(Tracker {
554547
config: config.clone(),
555-
database: database.clone(),
556548
whitelist_authorization: whitelist_authorization.clone(),
557549
in_memory_torrent_repository: in_memory_torrent_repository.clone(),
558550
db_torrent_repository: db_torrent_repository.clone(),
@@ -739,17 +731,6 @@ impl Tracker {
739731
pub fn cleanup_torrents(&self) {
740732
self.torrents_manager.cleanup_torrents();
741733
}
742-
743-
/// It drops the database tables.
744-
///
745-
/// # Errors
746-
///
747-
/// Will return `Err` if unable to drop tables.
748-
pub fn drop_database_tables(&self) -> Result<(), databases::error::Error> {
749-
// todo: this is only used for testing. We have to pass the database
750-
// reference directly to the tests instead of via the tracker.
751-
self.database.drop_database_tables()
752-
}
753734
}
754735

755736
#[must_use]
@@ -787,7 +768,7 @@ mod tests {
787768
let config = configuration::ephemeral_public();
788769

789770
let (
790-
database,
771+
_database,
791772
_in_memory_whitelist,
792773
whitelist_authorization,
793774
_authentication_service,
@@ -798,7 +779,6 @@ mod tests {
798779

799780
initialize_tracker(
800781
&config,
801-
&database,
802782
&whitelist_authorization,
803783
&in_memory_torrent_repository,
804784
&db_torrent_repository,
@@ -823,7 +803,6 @@ mod tests {
823803

824804
let tracker = initialize_tracker(
825805
&config,
826-
&database,
827806
&whitelist_authorization,
828807
&in_memory_torrent_repository,
829808
&db_torrent_repository,
@@ -838,7 +817,7 @@ mod tests {
838817
config.core.tracker_policy.persistent_torrent_completed_stat = true;
839818

840819
let (
841-
database,
820+
_database,
842821
_in_memory_whitelist,
843822
whitelist_authorization,
844823
_authentication_service,
@@ -849,7 +828,6 @@ mod tests {
849828

850829
initialize_tracker(
851830
&config,
852-
&database,
853831
&whitelist_authorization,
854832
&in_memory_torrent_repository,
855833
&db_torrent_repository,

src/core/services/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ use crate::core::Tracker;
3131
#[must_use]
3232
pub fn initialize_tracker(
3333
config: &Configuration,
34-
database: &Arc<Box<dyn Database>>,
3534
whitelist_authorization: &Arc<whitelist::authorization::Authorization>,
3635
in_memory_torrent_repository: &Arc<InMemoryTorrentRepository>,
3736
db_torrent_repository: &Arc<DatabasePersistentTorrentRepository>,
3837
torrents_manager: &Arc<TorrentsManager>,
3938
) -> Tracker {
4039
match Tracker::new(
4140
&Arc::new(config).core,
42-
database,
4341
whitelist_authorization,
4442
in_memory_torrent_repository,
4543
db_torrent_repository,

src/core/services/statistics/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ mod tests {
133133
let config = tracker_configuration();
134134

135135
let (
136-
database,
136+
_database,
137137
_in_memory_whitelist,
138138
whitelist_authorization,
139139
_authentication_service,
@@ -147,7 +147,6 @@ mod tests {
147147

148148
let tracker = Arc::new(initialize_tracker(
149149
&config,
150-
&database,
151150
&whitelist_authorization,
152151
&in_memory_torrent_repository,
153152
&db_torrent_repository,

src/core/services/torrent.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ mod tests {
119119

120120
fn initialize_tracker_and_deps(config: &Configuration) -> Arc<Tracker> {
121121
let (
122-
database,
122+
_database,
123123
_in_memory_whitelist,
124124
whitelist_authorization,
125125
_authentication_service,
@@ -130,7 +130,6 @@ mod tests {
130130

131131
Arc::new(initialize_tracker(
132132
config,
133-
&database,
134133
&whitelist_authorization,
135134
&in_memory_torrent_repository,
136135
&db_torrent_repository,
@@ -173,7 +172,7 @@ mod tests {
173172
let config = tracker_configuration();
174173

175174
let (
176-
database,
175+
_database,
177176
_in_memory_whitelist,
178177
whitelist_authorization,
179178
_authentication_service,
@@ -184,7 +183,6 @@ mod tests {
184183

185184
let tracker = initialize_tracker(
186185
&config,
187-
&database,
188186
&whitelist_authorization,
189187
&in_memory_torrent_repository,
190188
&db_torrent_repository,

src/servers/http/v1/handlers/announce.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -275,21 +275,20 @@ mod tests {
275275
/// Initialize tracker's dependencies and tracker.
276276
fn initialize_tracker_and_deps(config: &Configuration) -> TrackerAndDeps {
277277
let (
278-
database,
278+
_database,
279279
_in_memory_whitelist,
280280
whitelist_authorization,
281281
authentication_service,
282282
in_memory_torrent_repository,
283283
db_torrent_repository,
284284
torrents_manager,
285285
) = initialize_tracker_dependencies(config);
286-
286+
287287
let (stats_event_sender, _stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);
288288
let stats_event_sender = Arc::new(stats_event_sender);
289289

290290
let tracker = Arc::new(initialize_tracker(
291291
config,
292-
&database,
293292
&whitelist_authorization,
294293
&in_memory_torrent_repository,
295294
&db_torrent_repository,

src/servers/http/v1/handlers/scrape.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ mod tests {
152152
let config = configuration::ephemeral_private();
153153

154154
let (
155-
database,
155+
_database,
156156
_in_memory_whitelist,
157157
whitelist_authorization,
158158
authentication_service,
@@ -166,7 +166,6 @@ mod tests {
166166
(
167167
initialize_tracker(
168168
&config,
169-
&database,
170169
&whitelist_authorization,
171170
&in_memory_torrent_repository,
172171
&db_torrent_repository,
@@ -185,7 +184,7 @@ mod tests {
185184
let config = configuration::ephemeral_listed();
186185

187186
let (
188-
database,
187+
_database,
189188
_in_memory_whitelist,
190189
whitelist_authorization,
191190
authentication_service,
@@ -199,7 +198,6 @@ mod tests {
199198
(
200199
initialize_tracker(
201200
&config,
202-
&database,
203201
&whitelist_authorization,
204202
&in_memory_torrent_repository,
205203
&db_torrent_repository,
@@ -218,7 +216,7 @@ mod tests {
218216
let config = configuration::ephemeral_with_reverse_proxy();
219217

220218
let (
221-
database,
219+
_database,
222220
_in_memory_whitelist,
223221
whitelist_authorization,
224222
authentication_service,
@@ -232,7 +230,6 @@ mod tests {
232230
(
233231
initialize_tracker(
234232
&config,
235-
&database,
236233
&whitelist_authorization,
237234
&in_memory_torrent_repository,
238235
&db_torrent_repository,
@@ -251,7 +248,7 @@ mod tests {
251248
let config = configuration::ephemeral_without_reverse_proxy();
252249

253250
let (
254-
database,
251+
_database,
255252
_in_memory_whitelist,
256253
whitelist_authorization,
257254
authentication_service,
@@ -265,7 +262,6 @@ mod tests {
265262
(
266263
initialize_tracker(
267264
&config,
268-
&database,
269265
&whitelist_authorization,
270266
&in_memory_torrent_repository,
271267
&db_torrent_repository,

src/servers/http/v1/services/announce.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ mod tests {
7474
let config = configuration::ephemeral_public();
7575

7676
let (
77-
database,
77+
_database,
7878
_in_memory_whitelist,
7979
whitelist_authorization,
8080
_authentication_service,
@@ -87,7 +87,6 @@ mod tests {
8787

8888
let tracker = initialize_tracker(
8989
&config,
90-
&database,
9190
&whitelist_authorization,
9291
&in_memory_torrent_repository,
9392
&db_torrent_repository,
@@ -147,7 +146,7 @@ mod tests {
147146
let config = configuration::ephemeral();
148147

149148
let (
150-
database,
149+
_database,
151150
_in_memory_whitelist,
152151
whitelist_authorization,
153152
_authentication_service,
@@ -158,7 +157,6 @@ mod tests {
158157

159158
Tracker::new(
160159
&config.core,
161-
&database,
162160
&whitelist_authorization,
163161
&in_memory_torrent_repository,
164162
&db_torrent_repository,

src/servers/http/v1/services/scrape.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ mod tests {
8888
let config = configuration::ephemeral_public();
8989

9090
let (
91-
database,
91+
_database,
9292
_in_memory_whitelist,
9393
whitelist_authorization,
9494
_authentication_service,
@@ -99,7 +99,6 @@ mod tests {
9999

100100
initialize_tracker(
101101
&config,
102-
&database,
103102
&whitelist_authorization,
104103
&in_memory_torrent_repository,
105104
&db_torrent_repository,
@@ -131,7 +130,7 @@ mod tests {
131130
let config = configuration::ephemeral();
132131

133132
let (
134-
database,
133+
_database,
135134
_in_memory_whitelist,
136135
whitelist_authorization,
137136
_authentication_service,
@@ -142,7 +141,6 @@ mod tests {
142141

143142
Tracker::new(
144143
&config.core,
145-
&database,
146144
&whitelist_authorization,
147145
&in_memory_torrent_repository,
148146
&db_torrent_repository,

src/servers/udp/handlers.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,13 @@ mod tests {
525525
db_torrent_repository,
526526
torrents_manager,
527527
) = initialize_tracker_dependencies(config);
528-
528+
529529
let (stats_event_sender, _stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);
530530
let stats_event_sender = Arc::new(stats_event_sender);
531531
let whitelist_manager = initialize_whitelist_manager(database.clone(), in_memory_whitelist.clone());
532532

533533
let tracker = Arc::new(initialize_tracker(
534534
config,
535-
&database,
536535
&whitelist_authorization,
537536
&in_memory_torrent_repository,
538537
&db_torrent_repository,
@@ -646,7 +645,7 @@ mod tests {
646645
let config = tracker_configuration();
647646

648647
let (
649-
database,
648+
_database,
650649
_in_memory_whitelist,
651650
whitelist_authorization,
652651
_authentication_service,
@@ -658,7 +657,6 @@ mod tests {
658657
let tracker = Arc::new(
659658
Tracker::new(
660659
&config.core,
661-
&database,
662660
&whitelist_authorization,
663661
&in_memory_torrent_repository,
664662
&db_torrent_repository,
@@ -1411,7 +1409,7 @@ mod tests {
14111409
let config = Arc::new(TrackerConfigurationBuilder::default().with_external_ip("::126.0.0.1").into());
14121410

14131411
let (
1414-
database,
1412+
_database,
14151413
_in_memory_whitelist,
14161414
whitelist_authorization,
14171415
_authentication_service,
@@ -1432,7 +1430,6 @@ mod tests {
14321430
let tracker = Arc::new(
14331431
core::Tracker::new(
14341432
&config.core,
1435-
&database,
14361433
&whitelist_authorization,
14371434
&in_memory_torrent_repository,
14381435
&db_torrent_repository,

0 commit comments

Comments
 (0)