Fix memory issue caused by previous shallow copy
This commit is contained in:
parent
6320237326
commit
c842ac2343
@ -58,22 +58,10 @@ func NewServiceStatus(service *Service) *ServiceStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShallowCopy creates a shallow copy of ServiceStatus
|
// WithResultPagination returns a shallow copy of the ServiceStatus with only the results
|
||||||
func (ss *ServiceStatus) ShallowCopy() *ServiceStatus {
|
|
||||||
return &ServiceStatus{
|
|
||||||
Name: ss.Name,
|
|
||||||
Group: ss.Group,
|
|
||||||
Key: ss.Key,
|
|
||||||
Results: ss.Results,
|
|
||||||
Events: ss.Events,
|
|
||||||
Uptime: ss.Uptime,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithResultPagination makes a shallow copy of the ServiceStatus with only the results
|
|
||||||
// within the range defined by the page and pageSize parameters
|
// within the range defined by the page and pageSize parameters
|
||||||
func (ss *ServiceStatus) WithResultPagination(page, pageSize int) *ServiceStatus {
|
func (ss ServiceStatus) WithResultPagination(page, pageSize int) *ServiceStatus {
|
||||||
shallowCopy := ss.ShallowCopy()
|
shallowCopy := ss
|
||||||
numberOfResults := len(shallowCopy.Results)
|
numberOfResults := len(shallowCopy.Results)
|
||||||
start := numberOfResults - (page * pageSize)
|
start := numberOfResults - (page * pageSize)
|
||||||
end := numberOfResults - ((page - 1) * pageSize)
|
end := numberOfResults - ((page - 1) * pageSize)
|
||||||
@ -90,7 +78,7 @@ func (ss *ServiceStatus) WithResultPagination(page, pageSize int) *ServiceStatus
|
|||||||
} else {
|
} else {
|
||||||
shallowCopy.Results = shallowCopy.Results[start:end]
|
shallowCopy.Results = shallowCopy.Results[start:end]
|
||||||
}
|
}
|
||||||
return shallowCopy
|
return &shallowCopy
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddResult adds a Result to ServiceStatus.Results and makes sure that there are
|
// AddResult adds a Result to ServiceStatus.Results and makes sure that there are
|
||||||
|
@ -58,7 +58,7 @@ func (s *Store) GetServiceStatusByKey(key string) *core.ServiceStatus {
|
|||||||
if serviceStatus == nil {
|
if serviceStatus == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return serviceStatus.(*core.ServiceStatus).ShallowCopy()
|
return serviceStatus.(*core.ServiceStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert adds the observed result for the specified service into the store
|
// Insert adds the observed result for the specified service into the store
|
||||||
|
Loading…
x
Reference in New Issue
Block a user