|
@@ -41,14 +41,9 @@ func (c *memoryStore) Delete(id string) {
|
|
|
// List returns a sorted list of containers from the store.
|
|
|
// The containers are ordered by creation date.
|
|
|
func (c *memoryStore) List() []*Container {
|
|
|
- containers := new(History)
|
|
|
- c.RLock()
|
|
|
- for _, cont := range c.s {
|
|
|
- containers.Add(cont)
|
|
|
- }
|
|
|
- c.RUnlock()
|
|
|
+ containers := History(c.all())
|
|
|
containers.sort()
|
|
|
- return *containers
|
|
|
+ return containers
|
|
|
}
|
|
|
|
|
|
// Size returns the number of containers in the store.
|
|
@@ -60,9 +55,7 @@ func (c *memoryStore) Size() int {
|
|
|
|
|
|
// First returns the first container found in the store by a given filter.
|
|
|
func (c *memoryStore) First(filter StoreFilter) *Container {
|
|
|
- c.RLock()
|
|
|
- defer c.RUnlock()
|
|
|
- for _, cont := range c.s {
|
|
|
+ for _, cont := range c.all() {
|
|
|
if filter(cont) {
|
|
|
return cont
|
|
|
}
|
|
@@ -74,11 +67,8 @@ func (c *memoryStore) First(filter StoreFilter) *Container {
|
|
|
// This operation is asyncronous in the memory store.
|
|
|
// NOTE: Modifications to the store MUST NOT be done by the StoreReducer.
|
|
|
func (c *memoryStore) ApplyAll(apply StoreReducer) {
|
|
|
- c.RLock()
|
|
|
- defer c.RUnlock()
|
|
|
-
|
|
|
wg := new(sync.WaitGroup)
|
|
|
- for _, cont := range c.s {
|
|
|
+ for _, cont := range c.all() {
|
|
|
wg.Add(1)
|
|
|
go func(container *Container) {
|
|
|
apply(container)
|
|
@@ -89,4 +79,14 @@ func (c *memoryStore) ApplyAll(apply StoreReducer) {
|
|
|
wg.Wait()
|
|
|
}
|
|
|
|
|
|
+func (c *memoryStore) all() []*Container {
|
|
|
+ c.RLock()
|
|
|
+ containers := make([]*Container, 0, len(c.s))
|
|
|
+ for _, cont := range c.s {
|
|
|
+ containers = append(containers, cont)
|
|
|
+ }
|
|
|
+ c.RUnlock()
|
|
|
+ return containers
|
|
|
+}
|
|
|
+
|
|
|
var _ Store = &memoryStore{}
|