mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 11:57:50 +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
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"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.
|
// blocking the entire response. This does have a potential race condition, but that is fine.
|
||||||
if s.isProductionEnvironment {
|
if s.isProductionEnvironment {
|
||||||
go func() {
|
go func() {
|
||||||
span, ctx := tracer.StartSpanFromContext(ctx, "apiQueryHandler.incrementReadCount")
|
span, backgroundCtx := tracer.StartSpanFromContext(context.Background(), "apiQueryHandler.incrementReadCount")
|
||||||
err := s.db.IncrementEntryReadCountsForDevice(ctx, deviceId)
|
err := s.db.IncrementEntryReadCountsForDevice(backgroundCtx, deviceId)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("failed to increment read counts: %v\n", err)
|
||||||
|
}
|
||||||
span.Finish(tracer.WithError(err))
|
span.Finish(tracer.WithError(err))
|
||||||
}()
|
}()
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user