Further tweaking

This commit is contained in:
Neil Alexander 2022-01-31 10:32:31 +00:00
parent 2aea9601bb
commit 4ce69648a9
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
2 changed files with 14 additions and 14 deletions

View file

@ -157,7 +157,7 @@ func (r *downloadRequest) jsonErrorResponse(w http.ResponseWriter, res util.JSON
// Set status code and write the body // Set status code and write the body
w.WriteHeader(res.Code) w.WriteHeader(res.Code)
r.Logger.WithField("code", res.Code).Infof("Responding (%d bytes)", len(resBytes)) r.Logger.WithField("code", res.Code).Tracef("Responding (%d bytes)", len(resBytes))
// we don't really care that much if we fail to write the error response // we don't really care that much if we fail to write the error response
w.Write(resBytes) // nolint: errcheck w.Write(resBytes) // nolint: errcheck
@ -293,11 +293,11 @@ func (r *downloadRequest) respondFromLocalFile(
"Base64Hash": r.MediaMetadata.Base64Hash, "Base64Hash": r.MediaMetadata.Base64Hash,
"FileSizeBytes": r.MediaMetadata.FileSizeBytes, "FileSizeBytes": r.MediaMetadata.FileSizeBytes,
"ContentType": r.MediaMetadata.ContentType, "ContentType": r.MediaMetadata.ContentType,
}).Info("No good thumbnail found. Responding with original file.") }).Trace("No good thumbnail found. Responding with original file.")
responseFile = file responseFile = file
responseMetadata = r.MediaMetadata responseMetadata = r.MediaMetadata
} else { } else {
r.Logger.Info("Responding with thumbnail") r.Logger.Trace("Responding with thumbnail")
responseFile = thumbFile responseFile = thumbFile
responseMetadata = thumbMetadata.MediaMetadata responseMetadata = thumbMetadata.MediaMetadata
} }
@ -307,7 +307,7 @@ func (r *downloadRequest) respondFromLocalFile(
"Base64Hash": r.MediaMetadata.Base64Hash, "Base64Hash": r.MediaMetadata.Base64Hash,
"FileSizeBytes": r.MediaMetadata.FileSizeBytes, "FileSizeBytes": r.MediaMetadata.FileSizeBytes,
"ContentType": r.MediaMetadata.ContentType, "ContentType": r.MediaMetadata.ContentType,
}).Info("Responding with file") }).Trace("Responding with file")
responseFile = file responseFile = file
responseMetadata = r.MediaMetadata responseMetadata = r.MediaMetadata
if err := r.addDownloadFilenameToHeaders(w, responseMetadata); err != nil { if err := r.addDownloadFilenameToHeaders(w, responseMetadata); err != nil {
@ -436,7 +436,7 @@ func (r *downloadRequest) getThumbnailFile(
"Width": thumbnailSize.Width, "Width": thumbnailSize.Width,
"Height": thumbnailSize.Height, "Height": thumbnailSize.Height,
"ResizeMethod": thumbnailSize.ResizeMethod, "ResizeMethod": thumbnailSize.ResizeMethod,
}).Info("Pre-generating thumbnail for immediate response.") }).Debug("Pre-generating thumbnail for immediate response.")
thumbnail, err = r.generateThumbnail( thumbnail, err = r.generateThumbnail(
ctx, filePath, *thumbnailSize, activeThumbnailGeneration, ctx, filePath, *thumbnailSize, activeThumbnailGeneration,
maxThumbnailGenerators, db, maxThumbnailGenerators, db,
@ -574,7 +574,7 @@ func (r *downloadRequest) getMediaMetadataFromActiveRequest(activeRemoteRequests
defer activeRemoteRequests.Unlock() defer activeRemoteRequests.Unlock()
if activeRemoteRequestResult, ok := activeRemoteRequests.MXCToResult[mxcURL]; ok { if activeRemoteRequestResult, ok := activeRemoteRequests.MXCToResult[mxcURL]; ok {
r.Logger.Info("Waiting for another goroutine to fetch the remote file.") r.Logger.Trace("Waiting for another goroutine to fetch the remote file.")
// NOTE: Wait unlocks and locks again internally. There is still a deferred Unlock() that will unlock this. // NOTE: Wait unlocks and locks again internally. There is still a deferred Unlock() that will unlock this.
activeRemoteRequestResult.Cond.Wait() activeRemoteRequestResult.Cond.Wait()
@ -604,7 +604,7 @@ func (r *downloadRequest) broadcastMediaMetadata(activeRemoteRequests *types.Act
defer activeRemoteRequests.Unlock() defer activeRemoteRequests.Unlock()
mxcURL := "mxc://" + string(r.MediaMetadata.Origin) + "/" + string(r.MediaMetadata.MediaID) mxcURL := "mxc://" + string(r.MediaMetadata.Origin) + "/" + string(r.MediaMetadata.MediaID)
if activeRemoteRequestResult, ok := activeRemoteRequests.MXCToResult[mxcURL]; ok { if activeRemoteRequestResult, ok := activeRemoteRequests.MXCToResult[mxcURL]; ok {
r.Logger.Info("Signalling other goroutines waiting for this goroutine to fetch the file.") r.Logger.Trace("Signalling other goroutines waiting for this goroutine to fetch the file.")
activeRemoteRequestResult.MediaMetadata = r.MediaMetadata activeRemoteRequestResult.MediaMetadata = r.MediaMetadata
activeRemoteRequestResult.Error = err activeRemoteRequestResult.Error = err
activeRemoteRequestResult.Cond.Broadcast() activeRemoteRequestResult.Cond.Broadcast()
@ -635,7 +635,7 @@ func (r *downloadRequest) fetchRemoteFileAndStoreMetadata(
"UploadName": r.MediaMetadata.UploadName, "UploadName": r.MediaMetadata.UploadName,
"FileSizeBytes": r.MediaMetadata.FileSizeBytes, "FileSizeBytes": r.MediaMetadata.FileSizeBytes,
"ContentType": r.MediaMetadata.ContentType, "ContentType": r.MediaMetadata.ContentType,
}).Info("Storing file metadata to media repository database") }).Debug("Storing file metadata to media repository database")
// FIXME: timeout db request // FIXME: timeout db request
if err := db.StoreMediaMetadata(ctx, r.MediaMetadata); err != nil { if err := db.StoreMediaMetadata(ctx, r.MediaMetadata); err != nil {
@ -669,7 +669,7 @@ func (r *downloadRequest) fetchRemoteFileAndStoreMetadata(
"Base64Hash": r.MediaMetadata.Base64Hash, "Base64Hash": r.MediaMetadata.Base64Hash,
"FileSizeBytes": r.MediaMetadata.FileSizeBytes, "FileSizeBytes": r.MediaMetadata.FileSizeBytes,
"ContentType": r.MediaMetadata.ContentType, "ContentType": r.MediaMetadata.ContentType,
}).Infof("Remote file cached") }).Debug("Remote file cached")
return nil return nil
} }
@ -717,7 +717,7 @@ func (r *downloadRequest) fetchRemoteFile(
absBasePath config.Path, absBasePath config.Path,
maxFileSizeBytes config.FileSizeBytes, maxFileSizeBytes config.FileSizeBytes,
) (types.Path, bool, error) { ) (types.Path, bool, error) {
r.Logger.Info("Fetching remote file") r.Logger.Debug("Fetching remote file")
// create request for remote file // create request for remote file
resp, err := r.createRemoteRequest(ctx, client) resp, err := r.createRemoteRequest(ctx, client)
@ -762,7 +762,7 @@ func (r *downloadRequest) fetchRemoteFile(
} }
} }
r.Logger.Info("Transferring remote file") r.Logger.Trace("Transferring remote file")
// The file data is hashed but is NOT used as the MediaID, unlike in Upload. The hash is useful as a // The file data is hashed but is NOT used as the MediaID, unlike in Upload. The hash is useful as a
// method of deduplicating files to save storage, as well as a way to conduct // method of deduplicating files to save storage, as well as a way to conduct
@ -776,7 +776,7 @@ func (r *downloadRequest) fetchRemoteFile(
return "", false, errors.New("file could not be downloaded from remote server") return "", false, errors.New("file could not be downloaded from remote server")
} }
r.Logger.Info("Remote file transferred") r.Logger.Trace("Remote file transferred")
// It's possible the bytesWritten to the temporary file is different to the reported Content-Length from the remote // It's possible the bytesWritten to the temporary file is different to the reported Content-Length from the remote
// request's response. bytesWritten is therefore used as it is what would be sent to clients when reading from the local // request's response. bytesWritten is therefore used as it is what would be sent to clients when reading from the local
@ -790,7 +790,7 @@ func (r *downloadRequest) fetchRemoteFile(
return "", false, fmt.Errorf("fileutils.MoveFileWithHashCheck: %w", err) return "", false, fmt.Errorf("fileutils.MoveFileWithHashCheck: %w", err)
} }
if duplicate { if duplicate {
r.Logger.WithField("dst", finalPath).Info("File was stored previously - discarding duplicate") r.Logger.WithField("dst", finalPath).Trace("File was stored previously - discarding duplicate")
// Continue on to store the metadata in the database // Continue on to store the metadata in the database
} }

View file

@ -85,7 +85,7 @@ func (s *OutputClientDataConsumer) onMessage(msg *nats.Msg) {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"type": output.Type, "type": output.Type,
"room_id": output.RoomID, "room_id": output.RoomID,
}).Info("received data from client API server") }).Debug("Received data from client API server")
streamPos, err := s.db.UpsertAccountData( streamPos, err := s.db.UpsertAccountData(
s.ctx, userID, output.RoomID, output.Type, s.ctx, userID, output.RoomID, output.Type,