mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-28 17:23:09 -06:00
- Add $$NULL$$ string to be used when a part of the DocId is known to be NULL (#23)
- Use the $$NULL$$ for the known nullable use cases Co-authored-by: alexf@example.com <alexf@example.com>
This commit is contained in:
parent
db34c0950e
commit
49f8c7fe38
|
|
@ -16,6 +16,8 @@ type CosmosDocument struct {
|
|||
Timestamp int64 `json:"_ts"`
|
||||
}
|
||||
|
||||
var DocumentIdPartNullString string = "$$NULL$$"
|
||||
|
||||
func removeSpecialChars(docId string) string {
|
||||
// The following characters are restricted and cannot be used in the Id property: '/', '\', '?', '#'
|
||||
invalidChars := [4]string{"/", "\\", "?", "#"}
|
||||
|
|
@ -27,6 +29,13 @@ func removeSpecialChars(docId string) string {
|
|||
return result
|
||||
}
|
||||
|
||||
func EnsureIdPart(idPart string) string {
|
||||
if len(idPart) == 0 {
|
||||
return DocumentIdPartNullString
|
||||
}
|
||||
return idPart
|
||||
}
|
||||
|
||||
func GetDocumentId(tenantName string, collectionName string, id string) string {
|
||||
safeId := removeSpecialChars(id)
|
||||
return fmt.Sprintf("%s,%s,%s", collectionName, tenantName, safeId)
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ func ensureEventStateKeys(s *eventStateKeyStatements, ctx context.Context) {
|
|||
// ON CONFLICT DO NOTHING;
|
||||
|
||||
// event_state_key TEXT NOT NULL UNIQUE
|
||||
docId := ""
|
||||
docId := cosmosdbapi.EnsureIdPart("")
|
||||
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
|
||||
|
||||
data := eventStateKeysCosmos{
|
||||
|
|
|
|||
|
|
@ -137,7 +137,8 @@ func (s *accountDataStatements) InsertAccountData(
|
|||
}
|
||||
|
||||
// UNIQUE (user_id, room_id, type)
|
||||
docId := fmt.Sprintf("%s,%s,%s", userID, roomID, dataType)
|
||||
// roomId can be NULL
|
||||
docId := fmt.Sprintf("%s,%s,%s", userID, cosmosdbapi.EnsureIdPart(roomID), dataType)
|
||||
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
|
||||
|
||||
dbData, _ := getAccountDataType(s, ctx, s.getPartitionKey(), cosmosDocId)
|
||||
|
|
|
|||
|
|
@ -391,7 +391,8 @@ func (s *currentRoomStateStatements) UpsertRoomState(
|
|||
// )
|
||||
|
||||
// " ON CONFLICT (room_id, type, state_key)" +
|
||||
docId := fmt.Sprintf("%s,%s,%s", event.RoomID(), event.Type(), *event.StateKey())
|
||||
//StateKey can be NULL
|
||||
docId := fmt.Sprintf("%s,%s,%s", event.RoomID(), event.Type(), cosmosdbapi.EnsureIdPart(*event.StateKey()))
|
||||
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
|
||||
|
||||
membershipData := ""
|
||||
|
|
@ -556,7 +557,7 @@ func (s *currentRoomStateStatements) SelectStateEvent(
|
|||
var res []byte
|
||||
|
||||
// " ON CONFLICT (room_id, type, state_key)" +
|
||||
docId := fmt.Sprintf("%s,%s,%s", roomID, evType, stateKey)
|
||||
docId := fmt.Sprintf("%s,%s,%s", roomID, evType, cosmosdbapi.EnsureIdPart(stateKey))
|
||||
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
|
||||
var response, err = getEvent(s, ctx, s.getPartitionKey(), cosmosDocId)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue