fix: use actual particle child particle creation time

This was causing issues in which the last_child_created_at field for
stream particles was slightly after the actual particle's creation time,
and so comparing whether it's unseen merely via the playback markers
would be inaccurate.
This commit is contained in:
talksik
2026-03-30 13:52:40 -07:00
parent d10de739b3
commit 65ea901626
+27 -16
View File
@@ -102,7 +102,7 @@ func main() {
// --- Perform side effects --- // --- Perform side effects ---
updateParentLastChildCreatedAt(ctx, change.Doc.Ref) updateParentLastChildCreatedAt(ctx, change.Doc)
transcribeMediaParticle(ctx, depotSvc, speechSvc, change.Doc) transcribeMediaParticle(ctx, depotSvc, speechSvc, change.Doc)
if err := processingRepo.MarkProcessed(ctx, particleID); err != nil { if err := processingRepo.MarkProcessed(ctx, particleID); err != nil {
@@ -192,16 +192,18 @@ func toFirestoreTranscript(result *speech.TranscriptResult) particle.FirestoreTr
} }
} }
// updateParentLastChildCreatedAt updates the parent particle's field only if it's a particle of type stream // updateParentLastChildCreatedAt updates the parent stream's last_child_created_at
func updateParentLastChildCreatedAt(ctx context.Context, docRef *firestore.DocumentRef) { // to the child's actual created_at timestamp, so it stays directly comparable with
parentChildrenCollectionRef := docRef.Parent // playback markers (which also store child created_at values).
func updateParentLastChildCreatedAt(ctx context.Context, doc *firestore.DocumentSnapshot) {
parentChildrenCollectionRef := doc.Ref.Parent
if parentChildrenCollectionRef == nil { if parentChildrenCollectionRef == nil {
return return
} }
parentParticleDocRef := parentChildrenCollectionRef.Parent parentParticleDocRef := parentChildrenCollectionRef.Parent
if parentParticleDocRef == nil { if parentParticleDocRef == nil {
slog.Error("particle has no parent document", "particleID", docRef.ID) slog.Error("particle has no parent document", "particleID", doc.Ref.ID)
return return
} }
@@ -225,16 +227,25 @@ func updateParentLastChildCreatedAt(ctx context.Context, docRef *firestore.Docum
return return
} }
if particleType == particle.TypeStream { if particleType != particle.TypeStream {
slog.Info("going to update the last_child_created_at for parent particle") return
_, err = parentParticleDocRef.Update(ctx, []firestore.Update{ }
{
Path: "last_child_created_at", // Read the child's created_at — this is the same value that playback markers store
Value: firestore.ServerTimestamp, childCreatedAt, err := doc.DataAt("created_at")
}, if err != nil {
}) slog.Error("failed to read child created_at", "error", err, "particleID", doc.Ref.ID)
if err != nil { return
slog.Error("unable to update parent particle `last_child_created_at`") }
}
slog.Info("going to update the last_child_created_at for parent particle")
_, err = parentParticleDocRef.Update(ctx, []firestore.Update{
{
Path: "last_child_created_at",
Value: childCreatedAt,
},
})
if err != nil {
slog.Error("unable to update parent particle `last_child_created_at`")
} }
} }