mirror of
https://github.com/jsiebens/ionscale.git
synced 2026-03-31 15:07:49 +01:00
fix: show correct number of peers after switching accounts
This commit is contained in:
@@ -471,14 +471,14 @@ func (r *repository) ListMachineByTailnet(ctx context.Context, tailnetID uint64)
|
|||||||
return machines, nil
|
return machines, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *repository) ListMachinePeers(ctx context.Context, tailnetID uint64, key string) (Machines, error) {
|
func (r *repository) ListMachinePeers(ctx context.Context, tailnetID uint64, machineID uint64) (Machines, error) {
|
||||||
var machines = []Machine{}
|
var machines []Machine
|
||||||
|
|
||||||
tx := r.withContext(ctx).
|
tx := r.withContext(ctx).
|
||||||
Preload("Tailnet").
|
Preload("Tailnet").
|
||||||
Joins("User").
|
Joins("User").
|
||||||
Joins("User.Account").
|
Joins("User.Account").
|
||||||
Where("machines.tailnet_id = ? AND machines.machine_key <> ?", tailnetID, key).
|
Where("machines.tailnet_id = ? AND machines.id <> ?", tailnetID, machineID).
|
||||||
Order("machines.id asc").
|
Order("machines.id asc").
|
||||||
Find(&machines)
|
Find(&machines)
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ type Repository interface {
|
|||||||
CountMachineByTailnet(ctx context.Context, tailnetID uint64) (int64, error)
|
CountMachineByTailnet(ctx context.Context, tailnetID uint64) (int64, error)
|
||||||
DeleteMachineByTailnet(ctx context.Context, tailnetID uint64) error
|
DeleteMachineByTailnet(ctx context.Context, tailnetID uint64) error
|
||||||
DeleteMachineByUser(ctx context.Context, userID uint64) error
|
DeleteMachineByUser(ctx context.Context, userID uint64) error
|
||||||
ListMachinePeers(ctx context.Context, tailnetID uint64, key string) (Machines, error)
|
ListMachinePeers(ctx context.Context, tailnetID uint64, machineID uint64) (Machines, error)
|
||||||
ListInactiveEphemeralMachines(ctx context.Context, checkpoint time.Time) (Machines, error)
|
ListInactiveEphemeralMachines(ctx context.Context, checkpoint time.Time) (Machines, error)
|
||||||
SetMachineLastSeen(ctx context.Context, machineID uint64) error
|
SetMachineLastSeen(ctx context.Context, machineID uint64) error
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ func (h *PollNetMapper) CreateMapResponse(ctx context.Context, delta bool) (*Map
|
|||||||
syncedPeerIDs := map[uint64]bool{}
|
syncedPeerIDs := map[uint64]bool{}
|
||||||
|
|
||||||
if !h.req.OmitPeers {
|
if !h.req.OmitPeers {
|
||||||
candidatePeers, err := h.repository.ListMachinePeers(ctx, m.TailnetID, m.MachineKey)
|
candidatePeers, err := h.repository.ListMachinePeers(ctx, m.TailnetID, m.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ func TestSwitchAccounts(t *testing.T) {
|
|||||||
require.NoError(t, node.WaitFor(tsn.Connected()))
|
require.NoError(t, node.WaitFor(tsn.Connected()))
|
||||||
require.NoError(t, node.Check(tsn.HasUser("jane@localtest.me")))
|
require.NoError(t, node.Check(tsn.HasUser("jane@localtest.me")))
|
||||||
require.NoError(t, node.Check(tsn.HasName("switch-1")))
|
require.NoError(t, node.Check(tsn.HasName("switch-1")))
|
||||||
|
require.NoError(t, node.Check(tsn.PeerCount(1)))
|
||||||
|
|
||||||
machines := s.ListMachines(tailnet.Id)
|
machines := s.ListMachines(tailnet.Id)
|
||||||
require.Equal(t, 2, len(machines))
|
require.Equal(t, 2, len(machines))
|
||||||
|
|||||||
Reference in New Issue
Block a user