GetObjectsByParent get all objects under parent id
(parent string)
| 140 | |
| 141 | // GetObjectsByParent get all objects under parent id |
| 142 | func (c *Cache) GetObjectsByParent(parent string) ([]*APIObject, error) { |
| 143 | Log.Tracef("Getting children for %v", parent) |
| 144 | |
| 145 | objects := make([]*APIObject, 0) |
| 146 | c.db.View(func(tx *bolt.Tx) error { |
| 147 | cr := tx.Bucket(bParents).Cursor() |
| 148 | |
| 149 | // Iterate over all object ids stored under the parent in the index |
| 150 | objectIds := make([]string, 0) |
| 151 | prefix := []byte(parent + "/") |
| 152 | for k, v := cr.Seek(prefix); k != nil && bytes.HasPrefix(k, prefix); k, v = cr.Next() { |
| 153 | objectIds = append(objectIds, string(v)) |
| 154 | } |
| 155 | |
| 156 | // Fetch all objects for the given ids |
| 157 | for _, id := range objectIds { |
| 158 | if object, err := boltGetObject(tx, id); nil == err { |
| 159 | objects = append(objects, object) |
| 160 | } |
| 161 | } |
| 162 | return nil |
| 163 | }) |
| 164 | |
| 165 | Log.Tracef("Got objects from cache %v", objects) |
| 166 | return objects, nil |
| 167 | } |
| 168 | |
| 169 | // GetObjectByParentAndName finds a child element by name and its parent id |
| 170 | func (c *Cache) GetObjectByParentAndName(parent, name string) (object *APIObject, err error) { |
no test coverage detected