(ctx context.Context, file *ent.File)
| 904 | } |
| 905 | |
| 906 | func (f *fileClient) RemoveStaleEntities(ctx context.Context, file *ent.File) (StorageDiff, error) { |
| 907 | entities, err := file.Edges.EntitiesOrErr() |
| 908 | if err != nil { |
| 909 | return nil, fmt.Errorf("failed to get stale entities: %v", err) |
| 910 | } |
| 911 | |
| 912 | sizeReduced := int64(0) |
| 913 | ids := lo.FilterMap(entities, func(e *ent.Entity, index int) (int, bool) { |
| 914 | if e.ReferenceCount == 1 && e.UploadSessionID != nil { |
| 915 | sizeReduced += e.Size |
| 916 | return e.ID, true |
| 917 | } |
| 918 | |
| 919 | return 0, false |
| 920 | }) |
| 921 | |
| 922 | if len(ids) > 0 { |
| 923 | if err = f.client.Entity.Update(). |
| 924 | Where(entity.IDIn(ids...)). |
| 925 | RemoveFile(file). |
| 926 | AddReferenceCount(-1).Exec(ctx); err != nil { |
| 927 | return nil, fmt.Errorf("failed to remove stale entities: %v", err) |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | return map[int]int64{file.OwnerID: sizeReduced * -1}, nil |
| 932 | } |
| 933 | |
| 934 | func (f *fileClient) CreateEntity(ctx context.Context, file *ent.File, args *EntityParameters) (*ent.Entity, StorageDiff, error) { |
| 935 | createdBy := UserFromContext(ctx) |
nothing calls this directly
no test coverage detected