MCPcopy Create free account
hub / github.com/plexdrive/plexdrive / GetObjectsByParent

Method GetObjectsByParent

drive/cache.go:142–167  ·  view source on GitHub ↗

GetObjectsByParent get all objects under parent id

(parent string)

Source from the content-addressed store, hash-verified

140
141// GetObjectsByParent get all objects under parent id
142func (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
170func (c *Cache) GetObjectByParentAndName(parent, name string) (object *APIObject, err error) {

Callers 1

ReadDirAllMethod · 0.45

Calls 1

boltGetObjectFunction · 0.85

Tested by

no test coverage detected