Skip to content

Conversation

@erikdubbelboer
Copy link
Member

latency contains the average latency to all the peers in the lobby. This can be useful to filter on or sort by to find lobbies weer peers close to you.

@erikdubbelboer erikdubbelboer requested a review from Copilot October 5, 2025 03:04

This comment was marked as resolved.

`latency` contains the average latency to all the peers in the lobby.
This can be useful to filter on or sort by to find lobbies weer peers
close to you.

var lobbies []Lobby
rows, err := s.DB.Query(ctx, `
WITH lobbies AS (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: "lobbies" is also the table name, that might be confusing

latency += Math.round((performance.now() - start) / 2) // Divide by 2 to estimate one-way latency.
}

return Math.round(latency / pings) // Average of two measurements.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: two? or multiple

Comment on lines +429 to +456
now := util.NowUTC(ctx)

if len(latency) == 0 {
_, err := s.DB.Exec(ctx, `
UPDATE peers
SET
latency_vector = NULL,
updated_at = $1
WHERE peer = $2
`, now, peerID)
if err != nil {
return err
}
} else {
_, err := s.DB.Exec(ctx, `
UPDATE peers
SET
latency_vector = $1,
updated_at = $2
WHERE peer = $3
`, pgvector.NewVector(latency), now, peerID)
if err != nil {
return err
}
}

return nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we combine this?

	var latencyVec pgvector.Vector
	if len(latency) > 0 {
		latencyVec = pgvector.NewVector(latency)
	}

	_, err := s.DB.Exec(ctx, `
		UPDATE peers
		SET
			latency_vector = $1,
			updated_at = $2
		WHERE peer = $3
	`, latencyVec, now, peerID)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants