Add `Len()` to image store for info endpoint
In info, we only need the number of images, but `CountImages` was getting the whole map of images and then grabbing the length from that. This causes a lot of unnecessary CPU usage and memory allocations, which increases with O(n) on the number of images. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
bc7424b443
commit
f6a7763b6f
|
@ -77,7 +77,7 @@ type ImageService struct {
|
||||||
// CountImages returns the number of images stored by ImageService
|
// CountImages returns the number of images stored by ImageService
|
||||||
// called from info.go
|
// called from info.go
|
||||||
func (i *ImageService) CountImages() int {
|
func (i *ImageService) CountImages() int {
|
||||||
return len(i.imageStore.Map())
|
return i.imageStore.Len()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Children returns the children image.IDs for a parent image.
|
// Children returns the children image.IDs for a parent image.
|
||||||
|
|
|
@ -27,6 +27,7 @@ type Store interface {
|
||||||
Children(id ID) []ID
|
Children(id ID) []ID
|
||||||
Map() map[ID]*Image
|
Map() map[ID]*Image
|
||||||
Heads() map[ID]*Image
|
Heads() map[ID]*Image
|
||||||
|
Len() int
|
||||||
}
|
}
|
||||||
|
|
||||||
// LayerGetReleaser is a minimal interface for getting and releasing images.
|
// LayerGetReleaser is a minimal interface for getting and releasing images.
|
||||||
|
@ -336,3 +337,9 @@ func (is *store) imagesMap(all bool) map[ID]*Image {
|
||||||
}
|
}
|
||||||
return images
|
return images
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (is *store) Len() int {
|
||||||
|
is.RLock()
|
||||||
|
defer is.RUnlock()
|
||||||
|
return len(is.images)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue