mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 03:47:54 +02:00
Create background context for background update to ensure that the DB increment doesn't get terminated when the request finishes
This commit is contained in:
parent
1def4edc00
commit
218c70f5e7
@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
@ -121,8 +122,11 @@ func (s *Server) apiQueryHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// blocking the entire response. This does have a potential race condition, but that is fine.
|
||||
if s.isProductionEnvironment {
|
||||
go func() {
|
||||
span, ctx := tracer.StartSpanFromContext(ctx, "apiQueryHandler.incrementReadCount")
|
||||
err := s.db.IncrementEntryReadCountsForDevice(ctx, deviceId)
|
||||
span, backgroundCtx := tracer.StartSpanFromContext(context.Background(), "apiQueryHandler.incrementReadCount")
|
||||
err := s.db.IncrementEntryReadCountsForDevice(backgroundCtx, deviceId)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to increment read counts: %v\n", err)
|
||||
}
|
||||
span.Finish(tracer.WithError(err))
|
||||
}()
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user