MCPcopy Create free account
hub / github.com/cloudreve/cloudreve / loadOwner

Method loadOwner

ent/file_query.go:708–736  ·  view source on GitHub ↗
(ctx context.Context, query *UserQuery, nodes []*File, init func(*File), assign func(*File, *User))

Source from the content-addressed store, hash-verified

706}
707
708func (fq *FileQuery) loadOwner(ctx context.Context, query *UserQuery, nodes []*File, init func(*File), assign func(*File, *User)) error {
709 ids := make([]int, 0, len(nodes))
710 nodeids := make(map[int][]*File)
711 for i := range nodes {
712 fk := nodes[i].OwnerID
713 if _, ok := nodeids[fk]; !ok {
714 ids = append(ids, fk)
715 }
716 nodeids[fk] = append(nodeids[fk], nodes[i])
717 }
718 if len(ids) == 0 {
719 return nil
720 }
721 query.Where(user.IDIn(ids...))
722 neighbors, err := query.All(ctx)
723 if err != nil {
724 return err
725 }
726 for _, n := range neighbors {
727 nodes, ok := nodeids[n.ID]
728 if !ok {
729 return fmt.Errorf(`unexpected foreign-key "owner_id" returned %v`, n.ID)
730 }
731 for i := range nodes {
732 assign(nodes[i], n)
733 }
734 }
735 return nil
736}
737func (fq *FileQuery) loadStoragePolicies(ctx context.Context, query *StoragePolicyQuery, nodes []*File, init func(*File), assign func(*File, *StoragePolicy)) error {
738 ids := make([]int, 0, len(nodes))
739 nodeids := make(map[int][]*File)

Callers 1

sqlAllMethod · 0.95

Calls 3

IDInFunction · 0.92
WhereMethod · 0.45
AllMethod · 0.45

Tested by

no test coverage detected