@@ -3,18 +3,11 @@ package allocation
33import (
44 "context"
55 "encoding/json"
6- "fmt"
76 "path/filepath"
87 "sync"
98
10- "github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore"
11- "github.com/0chain/blobber/code/go/0chain.net/blobbercore/filestore"
129 "github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference"
1310 "github.com/0chain/blobber/code/go/0chain.net/core/common"
14- "github.com/0chain/blobber/code/go/0chain.net/core/logging"
15- "gorm.io/gorm"
16-
17- "go.uber.org/zap"
1811)
1912
2013var (
@@ -58,73 +51,8 @@ func (nf *DeleteFileChange) DeleteTempFile() error {
5851 return nil
5952}
6053
61- func (nf * DeleteFileChange ) CommitToFileStore (ctx context.Context , mut * sync.Mutex ) error {
62- db := datastore .GetStore ().GetTransaction (ctx )
63- type Result struct {
64- Id string
65- ValidationRoot string
66- ThumbnailHash string
67- FilestoreVersion int
68- }
69-
70- limitCh := make (chan struct {}, 10 )
71- wg := & sync.WaitGroup {}
72- var results []Result
73- mut .Lock ()
74- err := db .Model (& reference.Ref {}).Unscoped ().
75- Select ("id" , "validation_root" , "thumbnail_hash" , "filestore_version" ).
76- Where ("allocation_id=? AND path LIKE ? AND type=? AND deleted_at is not NULL" ,
77- nf .AllocationID , nf .Path + "%" , reference .FILE ).
78- FindInBatches (& results , 100 , func (tx * gorm.DB , batch int ) error {
79-
80- for _ , res := range results {
81- var count int64
82- tx .Model (& reference.Ref {}).
83- Where ("allocation_id=? AND validation_root=?" , nf .AllocationID , res .ValidationRoot ).
84- Count (& count )
85-
86- if count != 0 && res .ThumbnailHash == "" {
87- continue
88- }
89-
90- limitCh <- struct {}{}
91- wg .Add (1 )
92-
93- go func (res Result , count int64 ) {
94- defer func () {
95- <- limitCh
96- wg .Done ()
97- }()
98-
99- if count == 0 {
100- err := filestore .GetFileStore ().DeleteFile (nf .AllocationID , res .ValidationRoot , res .FilestoreVersion )
101- if err != nil {
102- logging .Logger .Error (fmt .Sprintf ("Error while deleting file: %s" , err .Error ()),
103- zap .String ("validation_root" , res .ValidationRoot ))
104- }
105- }
106- // We don't increase alloc size for thumbnail so we don't need to decrease it
107- // if res.ThumbnailHash != "" {
108- // err := filestore.GetFileStore().DeleteFile(nf.AllocationID, res.ThumbnailHash)
109- // if err != nil {
110- // logging.Logger.Error(fmt.Sprintf("Error while deleting thumbnail: %s", err.Error()),
111- // zap.String("thumbnail", res.ThumbnailHash))
112- // }
113- // }
114-
115- }(res , count )
116-
117- }
118- return nil
119- }).Error
120- mut .Unlock ()
121- wg .Wait ()
122-
123- return err
124- // return db.Model(&reference.Ref{}).Unscoped().
125- // Delete(&reference.Ref{},
126- // "allocation_id = ? AND path LIKE ? AND deleted_at IS NOT NULL",
127- // nf.AllocationID, nf.Path+"%").Error
54+ func (nf * DeleteFileChange ) CommitToFileStore (_ context.Context , _ * sync.Mutex ) error {
55+ return nil
12856}
12957
13058func (nf * DeleteFileChange ) GetPath () []string {
0 commit comments