Skip to content

Commit 2fa3608

Browse files
committed
...
1 parent 3742073 commit 2fa3608

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

internal/robot/client/cache/client.go

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func NewCachedRobotClient(rootDir string, httpClient *http.Client, baseURL strin
9090

9191
func (c *cacheRobotClient) ServerGet(id int) (*models.Server, error) {
9292
if c.shouldSync() {
93-
if _, err := c.sync(); err != nil {
93+
if _, err := c.ServerGetListForceRefresh(); err != nil {
9494
return nil, err
9595
}
9696
}
@@ -106,15 +106,32 @@ func (c *cacheRobotClient) ServerGet(id int) (*models.Server, error) {
106106

107107
func (c *cacheRobotClient) ServerGetList() ([]models.Server, error) {
108108
if c.shouldSync() {
109-
return c.sync()
109+
return c.ServerGetListForceRefresh()
110110
}
111111

112112
return c.l, nil
113113
}
114114

115115
// ServerGetListForceRefresh bypasses the timeout check and reloads the cache from Robot.
116116
func (c *cacheRobotClient) ServerGetListForceRefresh() ([]models.Server, error) {
117-
return c.sync()
117+
list, err := c.robotClient.ServerGetList()
118+
if err != nil {
119+
return list, err
120+
}
121+
122+
// populate list
123+
c.l = list
124+
125+
// remove all entries from map and repopulate it from the current list
126+
c.m = make(map[int]*models.Server)
127+
for i, server := range list {
128+
c.m[server.ServerNumber] = &list[i]
129+
}
130+
131+
// set time of last update
132+
c.lastUpdate = time.Now()
133+
134+
return c.l, nil
118135
}
119136

120137
func (c *cacheRobotClient) shouldSync() bool {
@@ -138,24 +155,3 @@ func (c *cacheRobotClient) SetCredentials(username, password string) error {
138155
c.m = nil
139156
return nil
140157
}
141-
142-
func (c *cacheRobotClient) sync() ([]models.Server, error) {
143-
list, err := c.robotClient.ServerGetList()
144-
if err != nil {
145-
return list, err
146-
}
147-
148-
// populate list
149-
c.l = list
150-
151-
// remove all entries from map and repopulate it from the current list
152-
c.m = make(map[int]*models.Server)
153-
for i, server := range list {
154-
c.m[server.ServerNumber] = &list[i]
155-
}
156-
157-
// set time of last update
158-
c.lastUpdate = time.Now()
159-
160-
return c.l, nil
161-
}

0 commit comments

Comments
 (0)