MCPcopy Index your code
hub / github.com/cloudreve/cloudreve / childFileQuery

Method childFileQuery

inventory/file_utils.go:118–155  ·  view source on GitHub ↗

ChildFileQuery generates query for child file(s) of a given set of root

(ownerID int, isSymbolic bool, root ...*ent.File)

Source from the content-addressed store, hash-verified

116
117// ChildFileQuery generates query for child file(s) of a given set of root
118func (f *fileClient) childFileQuery(ownerID int, isSymbolic bool, root ...*ent.File) *ent.FileQuery {
119 rawQuery := f.client.File.Query()
120 if len(root) == 1 && root[0] != nil {
121 // Query children of one single root
122 rawQuery = f.client.File.QueryChildren(root[0])
123 } else if root[0] == nil {
124 // Query orphan files with owner ID
125 predicates := []predicate.File{
126 file.NameNEQ(RootFolderName),
127 }
128
129 if ownerID > 0 {
130 predicates = append(predicates, file.OwnerIDEQ(ownerID))
131 }
132
133 if isSymbolic {
134 predicates = append(predicates, file.And(file.IsSymbolic(true), file.FileChildrenNotNil()))
135 } else {
136 predicates = append(predicates, file.Not(file.HasParent()))
137 }
138
139 rawQuery = f.client.File.Query().Where(
140 file.And(predicates...),
141 )
142 } else {
143 // Query children of multiple roots
144 rawQuery.
145 Where(
146 file.HasParentWith(
147 file.IDIn(lo.Map(root, func(item *ent.File, index int) int {
148 return item.ID
149 })...),
150 ),
151 )
152 }
153
154 return rawQuery
155}
156
157// batchInCondition returns a list of predicates that divide original group into smaller ones
158// to bypass DB limitations.

Callers 2

GetChildFileMethod · 0.95
GetChildFilesMethod · 0.95

Calls 12

NameNEQFunction · 0.92
OwnerIDEQFunction · 0.92
AndFunction · 0.92
IsSymbolicFunction · 0.92
FileChildrenNotNilFunction · 0.92
NotFunction · 0.92
HasParentFunction · 0.92
HasParentWithFunction · 0.92
IDInFunction · 0.92
QueryMethod · 0.45
QueryChildrenMethod · 0.45
WhereMethod · 0.45

Tested by

no test coverage detected