From 15aa629b6c30dd978eaa3aeaecab251614fdabec Mon Sep 17 00:00:00 2001 From: Christian Beutel <> Date: Wed, 16 Apr 2025 11:50:24 +0200 Subject: [PATCH] allows indexing to continue on error --- db/main.go | 6 ++++-- db/util/meilisearch.go | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/db/main.go b/db/main.go index 8b6b684e..171406ff 100644 --- a/db/main.go +++ b/db/main.go @@ -858,7 +858,8 @@ func bootstrapMeilisearchTrails(app core.App, client meilisearch.ServiceManager) return err } if err := util.IndexTrail(app, trail, author, client); err != nil { - return err + app.Logger().Warn(fmt.Sprintf("Unable to index trail '%s': %v", trail.GetString("name"), err)) + continue } shares, err := app.FindAllRecords("trail_share", @@ -874,7 +875,8 @@ func bootstrapMeilisearchTrails(app core.App, client meilisearch.ServiceManager) err = util.UpdateTrailShares(trail.Id, userIds, client) if err != nil { - return err + app.Logger().Warn(fmt.Sprintf("Unable to update trail shares '%s': %v", trail.GetString("name"), err)) + continue } } return nil diff --git a/db/util/meilisearch.go b/db/util/meilisearch.go index e129a933..122b3125 100644 --- a/db/util/meilisearch.go +++ b/db/util/meilisearch.go @@ -13,7 +13,7 @@ import ( "github.com/twpayne/go-polyline" ) -func documentFromTrailRecord(app core.App, r *core.Record, author *core.Record, includeShares bool) map[string]interface{} { +func documentFromTrailRecord(app core.App, r *core.Record, author *core.Record, includeShares bool) (map[string]interface{}, error) { photos := r.GetStringSlice("photos") thumbnail := "" if len(photos) > 0 { @@ -33,7 +33,7 @@ func documentFromTrailRecord(app core.App, r *core.Record, author *core.Record, polyline, err := getPolyline(app, r) if err != nil { - return nil + return nil, err } document := map[string]interface{}{ @@ -68,7 +68,7 @@ func documentFromTrailRecord(app core.App, r *core.Record, author *core.Record, document["shares"] = []string{} } - return document + return document, nil } func getPolyline(app core.App, r *core.Record) (string, error) { @@ -132,8 +132,11 @@ func IndexTrail(app core.App, r *core.Record, author *core.Record, client meilis if len(errs) > 0 { return fmt.Errorf("failed to expand: %v", errs) } - - documents := []map[string]interface{}{documentFromTrailRecord(app, r, author, true)} + doc, err := documentFromTrailRecord(app, r, author, true) + if err != nil { + return err + } + documents := []map[string]interface{}{doc} if _, err := client.Index("trails").AddDocuments(documents); err != nil { return err @@ -148,7 +151,11 @@ func UpdateTrail(app core.App, r *core.Record, author *core.Record, client meili return fmt.Errorf("failed to expand: %v", errs) } - documents := documentFromTrailRecord(app, r, author, false) + doc, err := documentFromTrailRecord(app, r, author, true) + if err != nil { + return err + } + documents := []map[string]interface{}{doc} if _, err := client.Index("trails").UpdateDocuments(documents); err != nil { return err