(ctx context.Context, values ...string)
| 86 | } |
| 87 | |
| 88 | func (p *Persister) MapStringsToUUIDs(ctx context.Context, values ...string) (uuids []uuid.UUID, err error) { |
| 89 | if len(values) == 0 { |
| 90 | return |
| 91 | } |
| 92 | |
| 93 | ctx, span := p.d.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.MapStringsToUUIDs", |
| 94 | trace.WithAttributes(attribute.Int("num_values", len(values)))) |
| 95 | defer otelx.End(span, &err) |
| 96 | |
| 97 | uuids, err = p.MapStringsToUUIDsReadOnly(ctx, values...) |
| 98 | if err != nil { |
| 99 | return nil, err |
| 100 | } |
| 101 | |
| 102 | p.d.Logger().WithField("values", values).WithField("UUIDs", uuids).Trace("adding UUID mappings") |
| 103 | |
| 104 | mappings := make([]UUIDMapping, len(values)) |
| 105 | for i := range values { |
| 106 | mappings[i] = UUIDMapping{ |
| 107 | ID: uuids[i], |
| 108 | StringRepresentation: values[i], |
| 109 | } |
| 110 | } |
| 111 | slices.SortFunc(mappings, func(a, b UUIDMapping) int { |
| 112 | return bytes.Compare(a.ID[:], b.ID[:]) |
| 113 | }) |
| 114 | mappings = slices.CompactFunc(mappings, func(a, b UUIDMapping) bool { |
| 115 | return a.ID == b.ID |
| 116 | }) |
| 117 | |
| 118 | span.SetAttributes(attribute.Int("num_mappings", len(mappings))) |
| 119 | |
| 120 | err = p.Transaction(ctx, func(ctx context.Context) error { |
| 121 | for chunk := range slices.Chunk(mappings, chunkSizeInsertUUIDMappings) { |
| 122 | query, args := buildInsertUUIDs(chunk, p.conn.Dialect.Name()) |
| 123 | if err := p.Connection(ctx).RawQuery(query, args...).Exec(); err != nil { |
| 124 | return sqlcon.HandleError(err) |
| 125 | } |
| 126 | } |
| 127 | return nil |
| 128 | }) |
| 129 | |
| 130 | return uuids, err |
| 131 | } |
| 132 | |
| 133 | func (p *Persister) MapStringsToUUIDsReadOnly(ctx context.Context, ss ...string) (uuids []uuid.UUID, err error) { |
| 134 | // This function doesn't talk to the database or do anything interesting, so we don't need to trace it. |
nothing calls this directly
no test coverage detected