Skip to content

Commit 0263f11

Browse files
committed
[Management] Surface SRV scores in interface.
1 parent 1fb3efa commit 0263f11

15 files changed

+120
-19
lines changed

nts-pool-management/.sqlx/query-171a166b3904d3adc72871e46be498526c402b598ad4ac3043581eb4e0b0ced6.json

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nts-pool-management/.sqlx/query-31d4ce07c537f10111af5dd81bdd7db63d70d3c6f962a3313bf7f9d345d28dde.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nts-pool-management/.sqlx/query-a3296570a3b04d48298edfae5077ef3c8ffd46003e473ae2a7f47a9f02c229da.json renamed to nts-pool-management/.sqlx/query-44206d6268686fd775902f78e6a7bce4475beef54273e55eb6a5d4e4e432108f.json

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nts-pool-management/.sqlx/query-cf52ea7a762ae47c59be4c52c2607a4bf6d6b344aa049a48084e1f39eaf66f0a.json renamed to nts-pool-management/.sqlx/query-7729918281e57a1b6e6878b4a4591b4ad6cfffc6b0ddc313880836d596506e47.json

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nts-pool-management/.sqlx/query-04b8a57bbfdebc759ceb2b2e6d90e31e7da655f41e8841d78c1434a0c678ff04.json renamed to nts-pool-management/.sqlx/query-951fff482611fe2ca35767a099eeedbd1e1db3327fafe3d36581448a02e933bb.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nts-pool-management/.sqlx/query-acba92643bcc269d133b46aa04f041acb0044c912b20115300af215a81b11e56.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nts-pool-management/.sqlx/query-707bc93558d6688e3618326a0c2d9b42e7c1d473689e6c2a245f5928804da46a.json renamed to nts-pool-management/.sqlx/query-fd146f11092591bda08a22cab9305185aa7b7a51c6ee79c21128208afb530253.json

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Add down migration script here
2+
DROP VIEW time_source_scores;
3+
CREATE VIEW time_source_scores AS WITH latest_per_monitor AS (
4+
SELECT DISTINCT ON (time_source_id, monitor_id, protocol) *
5+
FROM monitor_samples
6+
ORDER BY time_source_id, monitor_id, protocol, received_at DESC
7+
),
8+
best_per_source AS (
9+
SELECT DISTINCT ON (time_source_id, protocol) *
10+
FROM latest_per_monitor
11+
ORDER BY time_source_id, protocol, score DESC
12+
)
13+
SELECT ts.*, COALESCE(v4.score, 0) AS "ipv4_score", COALESCE(v6.score, 0) AS "ipv6_score"
14+
FROM time_sources AS ts
15+
LEFT JOIN best_per_source AS v4 ON v4.time_source_id = ts.id AND v4.protocol = 'ipv4'
16+
LEFT JOIN best_per_source AS v6 ON v6.time_source_id = ts.id AND v6.protocol = 'ipv6';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Add up migration script here
2+
DROP VIEW time_source_scores;
3+
CREATE VIEW time_source_scores AS WITH latest_per_monitor AS (
4+
SELECT DISTINCT ON (time_source_id, monitor_id, protocol) *
5+
FROM monitor_samples
6+
ORDER BY time_source_id, monitor_id, protocol, received_at DESC
7+
),
8+
best_per_source AS (
9+
SELECT DISTINCT ON (time_source_id, protocol) *
10+
FROM latest_per_monitor
11+
ORDER BY time_source_id, protocol, score DESC
12+
)
13+
SELECT ts.*, COALESCE(v4.score, 0) AS "ipv4_score", COALESCE(v6.score, 0) AS "ipv6_score", COALESCE(srv4.score, 0) AS "srv4_score", COALESCE(srv6.score, 0) AS "srv6_score"
14+
FROM time_sources AS ts
15+
LEFT JOIN best_per_source AS v4 ON v4.time_source_id = ts.id AND v4.protocol = 'ipv4'
16+
LEFT JOIN best_per_source AS v6 ON v6.time_source_id = ts.id AND v6.protocol = 'ipv6'
17+
LEFT JOIN best_per_source AS srv4 ON srv4.time_source_id = ts.id AND srv4.protocol = 'srvv4'
18+
LEFT JOIN best_per_source AS srv6 ON srv6.time_source_id = ts.id AND srv6.protocol = 'srvv6';

nts-pool-management/src/models/time_source.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub struct TimeSource {
4242
pub weight: i32,
4343
pub ipv4_score: f64,
4444
pub ipv6_score: f64,
45+
pub srv4_score: f64,
46+
pub srv6_score: f64,
4547
}
4648

4749
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
@@ -373,7 +375,9 @@ pub async fn details(
373375
base_secret_index AS "base_secret_index!",
374376
weight AS "weight!",
375377
ipv4_score AS "ipv4_score!: _",
376-
ipv6_score AS "ipv6_score!: _"
378+
ipv6_score AS "ipv6_score!: _",
379+
srv4_score AS "srv4_score!: _",
380+
srv6_score AS "srv6_score!: _"
377381
FROM time_source_scores
378382
WHERE id = $1 AND deleted = false;
379383
"#,
@@ -400,7 +404,9 @@ pub async fn by_user(
400404
base_secret_index AS "base_secret_index!",
401405
weight AS "weight!",
402406
ipv4_score AS "ipv4_score!: _",
403-
ipv6_score AS "ipv6_score!: _"
407+
ipv6_score AS "ipv6_score!: _",
408+
srv4_score AS "srv4_score!: _",
409+
srv6_score AS "srv6_score!: _"
404410
FROM time_source_scores
405411
WHERE owner = $1 AND deleted = false;
406412
"#,
@@ -424,7 +430,9 @@ pub async fn list(conn: impl DbConnLike<'_>) -> Result<Vec<TimeSource>, sqlx::Er
424430
base_secret_index AS "base_secret_index!",
425431
weight AS "weight!",
426432
ipv4_score AS "ipv4_score!: _",
427-
ipv6_score AS "ipv6_score!: _"
433+
ipv6_score AS "ipv6_score!: _",
434+
srv4_score AS "srv4_score!: _",
435+
srv6_score AS "srv6_score!: _"
428436
FROM time_source_scores
429437
WHERE deleted = false;
430438
"#,
@@ -456,7 +464,9 @@ pub async fn list_with_owner_names(
456464
ts.base_secret_index,
457465
ts.weight,
458466
ts.ipv4_score,
459-
ts.ipv6_score
467+
ts.ipv6_score,
468+
ts.srv4_score,
469+
ts.srv6_score
460470
) AS "time_source!: TimeSource",
461471
u.email AS "user_email!"
462472
FROM time_source_scores AS ts

0 commit comments

Comments
 (0)