Skip to content

Commit

Permalink
also invalidate cache if events are disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Sep 23, 2022
1 parent 4b0d436 commit 17181b9
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions pkg/rhttp/datatx/manager/tus/tus.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,41 +96,40 @@ func (m *manager) Handler(fs storage.FS) (http.Handler, error) {
// let the composable storage tell tus which extensions it supports
composable.UseIn(composer)

publishEvents := m.publisher != nil
config := tusd.Config{
StoreComposer: composer,
NotifyCompleteUploads: publishEvents,
NotifyCompleteUploads: true,
}

handler, err := tusd.NewUnroutedHandler(config)
if err != nil {
return nil, err
}

if publishEvents {
go func() {
for {
ev := <-handler.CompleteUploads
info := ev.Upload
owner := &userv1beta1.UserId{
Idp: info.Storage["Idp"],
OpaqueId: info.Storage["UserId"],
}
ref := &provider.Reference{
ResourceId: &provider.ResourceId{
StorageId: info.MetaData["providerID"],
SpaceId: info.Storage["SpaceRoot"],
OpaqueId: info.Storage["SpaceRoot"],
},
Path: utils.MakeRelativePath(filepath.Join(info.MetaData["dir"], info.MetaData["filename"])),
}
datatx.InvalidateCache(owner, ref, m.statCache)
go func() {
for {
ev := <-handler.CompleteUploads
info := ev.Upload
owner := &userv1beta1.UserId{
Idp: info.Storage["Idp"],
OpaqueId: info.Storage["UserId"],
}
ref := &provider.Reference{
ResourceId: &provider.ResourceId{
StorageId: info.MetaData["providerID"],
SpaceId: info.Storage["SpaceRoot"],
OpaqueId: info.Storage["SpaceRoot"],
},
Path: utils.MakeRelativePath(filepath.Join(info.MetaData["dir"], info.MetaData["filename"])),
}
datatx.InvalidateCache(owner, ref, m.statCache)
if m.publisher != nil {
if err := datatx.EmitFileUploadedEvent(owner, ref, m.publisher); err != nil {
appctx.GetLogger(context.Background()).Error().Err(err).Msg("failed to publish FileUploaded event")
}
}
}()
}
}
}()

h := handler.Middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
method := r.Method
Expand Down

0 comments on commit 17181b9

Please sign in to comment.