Skip to content

Commit a19aaef

Browse files
Fix suggestions
1 parent 78b5f9f commit a19aaef

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

internal/signaling/stores/postgres.go

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func (s *PostgresStore) ListLobbies(ctx context.Context, game string, latency []
354354

355355
var lobbies []Lobby
356356
rows, err := s.DB.Query(ctx, `
357-
WITH lobbies AS (
357+
WITH game_lobbies AS (
358358
SELECT
359359
code,
360360
COALESCE(ARRAY_LENGTH(peers, 1), 0) AS "playerCount",
@@ -382,7 +382,7 @@ func (s *PostgresStore) ListLobbies(ctx context.Context, game string, latency []
382382
AND public = true
383383
)
384384
SELECT *
385-
FROM lobbies
385+
FROM game_lobbies
386386
WHERE `+where+`
387387
ORDER BY `+order+`
388388
LIMIT $3
@@ -428,28 +428,20 @@ func (s *PostgresStore) CreatePeer(ctx context.Context, peerID, secret, gameID s
428428
func (s *PostgresStore) UpdatePeerLatency(ctx context.Context, peerID string, latency []float32) error {
429429
now := util.NowUTC(ctx)
430430

431-
if len(latency) == 0 {
432-
_, err := s.DB.Exec(ctx, `
433-
UPDATE peers
434-
SET
435-
latency_vector = NULL,
436-
updated_at = $1
437-
WHERE peer = $2
438-
`, now, peerID)
439-
if err != nil {
440-
return err
441-
}
442-
} else {
443-
_, err := s.DB.Exec(ctx, `
444-
UPDATE peers
445-
SET
446-
latency_vector = $1,
447-
updated_at = $2
448-
WHERE peer = $3
449-
`, pgvector.NewVector(latency), now, peerID)
450-
if err != nil {
451-
return err
452-
}
431+
var vec *pgvector.Vector
432+
if len(latency) > 0 {
433+
v := pgvector.NewVector(latency)
434+
vec = &v
435+
}
436+
_, err := s.DB.Exec(ctx, `
437+
UPDATE peers
438+
SET
439+
latency_vector = $1,
440+
updated_at = $2
441+
WHERE peer = $3
442+
`, vec, now, peerID)
443+
if err != nil {
444+
return err
453445
}
454446

455447
return nil

lib/network-latency.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function getLatencyVector (max: number, pings: number): Promise<num
3030
latency += Math.round((performance.now() - start) / 2) // Divide by 2 to estimate one-way latency.
3131
}
3232

33-
return Math.round(latency / pings) // Average of two measurements.
33+
return Math.round(latency / pings) // Average of multiple measurements.
3434
}))
3535
return measurements
3636
}

0 commit comments

Comments
 (0)