MCPcopy
hub / github.com/ory/keto / MapStringsToUUIDs

Method MapStringsToUUIDs

internal/persistence/sql/uuid_mapping.go:88–131  ·  view source on GitHub ↗
(ctx context.Context, values ...string)

Source from the content-addressed store, hash-verified

86}
87
88func (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
133func (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.

Callers

nothing calls this directly

Implementers 1

Persisterinternal/persistence/sql/persister.go

Calls 9

TransactionMethod · 0.95
ConnectionMethod · 0.95
buildInsertUUIDsFunction · 0.85
WithFieldMethod · 0.80
TracerMethod · 0.65
LoggerMethod · 0.65
ExecMethod · 0.65
NameMethod · 0.45

Tested by

no test coverage detected