| 452 | } |
| 453 | |
| 454 | func (sq *ShareQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*Share, init func(*Share), assign func(*Share, *User)) error { |
| 455 | ids := make([]int, 0, len(nodes)) |
| 456 | nodeids := make(map[int][]*Share) |
| 457 | for i := range nodes { |
| 458 | if nodes[i].user_shares == nil { |
| 459 | continue |
| 460 | } |
| 461 | fk := *nodes[i].user_shares |
| 462 | if _, ok := nodeids[fk]; !ok { |
| 463 | ids = append(ids, fk) |
| 464 | } |
| 465 | nodeids[fk] = append(nodeids[fk], nodes[i]) |
| 466 | } |
| 467 | if len(ids) == 0 { |
| 468 | return nil |
| 469 | } |
| 470 | query.Where(user.IDIn(ids...)) |
| 471 | neighbors, err := query.All(ctx) |
| 472 | if err != nil { |
| 473 | return err |
| 474 | } |
| 475 | for _, n := range neighbors { |
| 476 | nodes, ok := nodeids[n.ID] |
| 477 | if !ok { |
| 478 | return fmt.Errorf(`unexpected foreign-key "user_shares" returned %v`, n.ID) |
| 479 | } |
| 480 | for i := range nodes { |
| 481 | assign(nodes[i], n) |
| 482 | } |
| 483 | } |
| 484 | return nil |
| 485 | } |
| 486 | func (sq *ShareQuery) loadFile(ctx context.Context, query *FileQuery, nodes []*Share, init func(*Share), assign func(*Share, *File)) error { |
| 487 | ids := make([]int, 0, len(nodes)) |
| 488 | nodeids := make(map[int][]*Share) |