Skip to content

Commit

Permalink
fix timeline ids
Browse files Browse the repository at this point in the history
  • Loading branch information
totegamma committed Mar 30, 2024
1 parent 3eb5e2d commit a25b48a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions x/timeline/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,24 @@ func (r *repository) GetTimeline(ctx context.Context, key string) (core.Timeline
ctx, span := tracer.Start(ctx, "RepositoryGetTimeline")
defer span.End()

if len(key) == 27 {
if key[0] != 't' {
return core.Timeline{}, fmt.Errorf("timeline typed-id must start with 't'")
}
key = key[1:]
}

var timeline core.Timeline
err := r.db.WithContext(ctx).First(&timeline, "id = ?", key).Error

schemaUrl, err := r.schema.IDToUrl(ctx, timeline.SchemaID)
if err != nil {
return timeline, err
}
timeline.Schema = schemaUrl

timeline.ID = "t" + timeline.ID

return timeline, err
}

Expand All @@ -526,6 +542,8 @@ func (r *repository) CreateTimeline(ctx context.Context, timeline core.Timeline)

r.mc.Increment("timeline_count", 1)

timeline.ID = "t" + timeline.ID

return timeline, err
}

Expand Down

0 comments on commit a25b48a

Please sign in to comment.