core: Do not emit post-receive hook when the offset didn't change
This commit is contained in:
parent
966711019b
commit
6de723ec8b
|
@ -43,7 +43,7 @@ This event will be triggered after an upload has been terminated, meaning that t
|
|||
|
||||
### post-receive
|
||||
|
||||
This event will be triggered for every running upload to indicate its current progress. It will occur for each open PATCH request, every second. The offset property will be set to the number of bytes which have been transfered to the server, at the time in total. Please be aware that this number may be higher than the number of bytes which have been stored by the data store!
|
||||
This event will be triggered for every running upload to indicate its current progress. It will be emitted whenever the server has received more data from the client but at most every second. The offset property will be set to the number of bytes which have been transfered to the server, at the time in total. Please be aware that this number may be higher than the number of bytes which have been stored by the data store!
|
||||
|
||||
|
||||
## File Hooks
|
||||
|
|
|
@ -458,10 +458,8 @@ func TestPatch(t *testing.T) {
|
|||
|
||||
writer.Close()
|
||||
|
||||
info = <-c
|
||||
a.Equal("yes", info.ID)
|
||||
a.Equal(int64(100), info.Size)
|
||||
a.Equal(int64(18), info.Offset)
|
||||
// No progress event is sent after the writer is closed
|
||||
// because an event for 18 bytes was already emitted.
|
||||
}()
|
||||
|
||||
(&httpTest{
|
||||
|
|
|
@ -822,6 +822,7 @@ func (w *progressWriter) Write(b []byte) (int, error) {
|
|||
// It will stop sending these instances once the returned channel has been
|
||||
// closed. The returned reader should be used to read the request body.
|
||||
func (handler *UnroutedHandler) sendProgressMessages(info FileInfo, reader io.Reader) (io.Reader, chan<- struct{}) {
|
||||
previousOffset := int64(0)
|
||||
progress := &progressWriter{
|
||||
Offset: info.Offset,
|
||||
}
|
||||
|
@ -833,11 +834,17 @@ func (handler *UnroutedHandler) sendProgressMessages(info FileInfo, reader io.Re
|
|||
select {
|
||||
case <-stop:
|
||||
info.Offset = atomic.LoadInt64(&progress.Offset)
|
||||
if info.Offset != previousOffset {
|
||||
handler.UploadProgress <- info
|
||||
previousOffset = info.Offset
|
||||
}
|
||||
return
|
||||
case <-time.After(1 * time.Second):
|
||||
info.Offset = atomic.LoadInt64(&progress.Offset)
|
||||
if info.Offset != previousOffset {
|
||||
handler.UploadProgress <- info
|
||||
previousOffset = info.Offset
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue