allows indexing to continue on error

This commit is contained in:
Christian Beutel
2025-04-16 11:50:24 +02:00
parent e2b4818af9
commit 15aa629b6c
2 changed files with 17 additions and 8 deletions

View File

@@ -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

View File

@@ -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