stringTuplesToNumericTuples converts the string state key tuples into numeric IDs If there isn't a numeric ID for either the event type or the event state key then the tuple is discarded. Returns an error if there was a problem talking to the database.
( ctx context.Context, stringTuples []gomatrixserverlib.StateKeyTuple, )
| 306 | // If there isn't a numeric ID for either the event type or the event state key then the tuple is discarded. |
| 307 | // Returns an error if there was a problem talking to the database. |
| 308 | func (v *StateResolution) stringTuplesToNumericTuples( |
| 309 | ctx context.Context, |
| 310 | stringTuples []gomatrixserverlib.StateKeyTuple, |
| 311 | ) ([]types.StateKeyTuple, error) { |
| 312 | span, ctx := opentracing.StartSpanFromContext(ctx, "StateResolution.stringTuplesToNumericTuples") |
| 313 | defer span.Finish() |
| 314 | |
| 315 | eventTypes := make([]string, len(stringTuples)) |
| 316 | stateKeys := make([]string, len(stringTuples)) |
| 317 | for i := range stringTuples { |
| 318 | eventTypes[i] = stringTuples[i].EventType |
| 319 | stateKeys[i] = stringTuples[i].StateKey |
| 320 | } |
| 321 | eventTypes = util.UniqueStrings(eventTypes) |
| 322 | eventTypeMap, err := v.db.EventTypeNIDs(ctx, eventTypes) |
| 323 | if err != nil { |
| 324 | return nil, err |
| 325 | } |
| 326 | stateKeys = util.UniqueStrings(stateKeys) |
| 327 | stateKeyMap, err := v.db.EventStateKeyNIDs(ctx, stateKeys) |
| 328 | if err != nil { |
| 329 | return nil, err |
| 330 | } |
| 331 | |
| 332 | var result []types.StateKeyTuple |
| 333 | for _, stringTuple := range stringTuples { |
| 334 | var numericTuple types.StateKeyTuple |
| 335 | var ok1, ok2 bool |
| 336 | numericTuple.EventTypeNID, ok1 = eventTypeMap[stringTuple.EventType] |
| 337 | numericTuple.EventStateKeyNID, ok2 = stateKeyMap[stringTuple.StateKey] |
| 338 | // Discard the tuple if there wasn't a numeric ID for either the event type or the state key. |
| 339 | if ok1 && ok2 { |
| 340 | result = append(result, numericTuple) |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | return result, nil |
| 345 | } |
| 346 | |
| 347 | // loadStateAtSnapshotForNumericTuples loads the state for a list of event type and state key pairs at a snapshot. |
| 348 | // This is used when we only want to load a subset of the room state at a snapshot. |
no test coverage detected