- Make the CosmosDocId use commas as separators instead of underscore to match Messaging (#22)

- Make the DocId for StateBlock to be bas64 and not hex

Co-authored-by: alexf@example.com <alexf@example.com>
This commit is contained in:
alexfca 2021-10-01 10:02:23 +10:00 committed by GitHub
parent 2e168ee5ea
commit db34c0950e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 61 additions and 62 deletions

View file

@ -149,7 +149,7 @@ func (s *inboundPeeksStatements) InsertInboundPeek(
// stmt := sqlutil.TxStmt(txn, s.insertInboundPeekStmt)
// UNIQUE (room_id, server_name, peek_id)
docId := fmt.Sprintf("%s_%s_%s", roomID, serverName, peekID)
docId := fmt.Sprintf("%s,%s,%s", roomID, serverName, peekID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, _ := getInboundPeek(s, ctx, s.getPartitionKey(roomID), cosmosDocId)
@ -193,7 +193,7 @@ func (s *inboundPeeksStatements) RenewInboundPeek(
// _, err = sqlutil.TxStmt(txn, s.renewInboundPeekStmt).ExecContext(ctx, nowMilli, renewalInterval, roomID, serverName, peekID)
// UNIQUE (room_id, server_name, peek_id)
docId := fmt.Sprintf("%s_%s_%s", roomID, serverName, peekID)
docId := fmt.Sprintf("%s,%s,%s", roomID, serverName, peekID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
// _, err = sqlutil.TxStmt(txn, s.renewInboundPeekStmt).ExecContext(ctx, nowMilli, renewalInterval, roomID, serverName, peekID)
@ -222,7 +222,7 @@ func (s *inboundPeeksStatements) SelectInboundPeek(
// "SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationsender_inbound_peeks WHERE room_id = $1 and server_name = $2 and peek_id = $3"
// UNIQUE (room_id, server_name, peek_id)
docId := fmt.Sprintf("%s_%s_%s", roomID, serverName, peekID)
docId := fmt.Sprintf("%s,%s,%s", roomID, serverName, peekID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getPartitionKey(roomID), docId)
// row := sqlutil.TxStmt(txn, s.selectInboundPeeksStmt).QueryRowContext(ctx, roomID)

View file

@ -145,7 +145,7 @@ func (s *outboundPeeksStatements) InsertOutboundPeek(
// stmt := sqlutil.TxStmt(txn, s.insertOutboundPeekStmt)
nowMilli := time.Now().UnixNano() / int64(time.Millisecond)
// UNIQUE (room_id, server_name, peek_id)
docId := fmt.Sprintf("%s_%s_%s", roomID, serverName, peekID)
docId := fmt.Sprintf("%s,%s,%s", roomID, serverName, peekID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, _ := getOutboundPeek(s, ctx, s.getPartitionKey(roomID), cosmosDocId)
@ -190,7 +190,7 @@ func (s *outboundPeeksStatements) RenewOutboundPeek(
nowMilli := time.Now().UnixNano() / int64(time.Millisecond)
// UNIQUE (room_id, server_name, peek_id)
docId := fmt.Sprintf("%s_%s_%s", roomID, serverName, peekID)
docId := fmt.Sprintf("%s,%s,%s", roomID, serverName, peekID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
// _, err = sqlutil.TxStmt(txn, s.renewOutboundPeekStmt).ExecContext(ctx, nowMilli, renewalInterval, roomID, serverName, peekID)
@ -219,7 +219,7 @@ func (s *outboundPeeksStatements) SelectOutboundPeek(
// "SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationsender_outbound_peeks WHERE room_id = $1 and server_name = $2 and peek_id = $3"
// UNIQUE (room_id, server_name, peek_id)
docId := fmt.Sprintf("%s_%s_%s", roomID, serverName, peekID)
docId := fmt.Sprintf("%s,%s,%s", roomID, serverName, peekID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
// row := sqlutil.TxStmt(txn, s.selectOutboundPeeksStmt).QueryRowContext(ctx, roomID)

View file

@ -145,7 +145,7 @@ func (s *queueEDUsStatements) InsertQueueEDU(
// CREATE UNIQUE INDEX IF NOT EXISTS federationsender_queue_edus_json_nid_idx
// ON federationsender_queue_edus (json_nid, server_name);
docId := fmt.Sprintf("%d_%s", nid, eduType)
docId := fmt.Sprintf("%d,%s", nid, eduType)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
data := queueEDUCosmos{

View file

@ -157,7 +157,7 @@ func (s *queuePDUsStatements) InsertQueuePDU(
// CREATE UNIQUE INDEX IF NOT EXISTS federationsender_queue_pdus_pdus_json_nid_idx
// ON federationsender_queue_pdus (json_nid, server_name);
docId := fmt.Sprintf("%d_%s", nid, serverName)
docId := fmt.Sprintf("%d,%s", nid, serverName)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
data := queuePDUCosmos{

View file

@ -86,7 +86,7 @@ type PartitionOffsetStatements struct {
func (s PartitionOffsetStatements) getCollectionName() string {
// Include the Prefix
tableName := fmt.Sprintf("%s_%s", s.prefix, s.tableName)
tableName := fmt.Sprintf("%s,%s", s.prefix, s.tableName)
return cosmosdbapi.GetCollectionName(s.db.DatabaseName, tableName)
}
@ -193,7 +193,7 @@ func (s *PartitionOffsetStatements) upsertPartitionOffset(
// stmt := TxStmt(txn, s.upsertPartitionOffsetStmt)
// UNIQUE (topic, partition)
docId := fmt.Sprintf("%s_%d", topic, partition)
docId := fmt.Sprintf("%s,%d", topic, partition)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.CosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, _ := getPartitionOffset(s, ctx, s.getPartitionKey(topic), cosmosDocId)

View file

@ -299,7 +299,7 @@ func (t *topicsStatements) InsertTopics(
// stmt := sqlutil.TxStmt(txn, t.insertTopicsStmt)
// UNIQUE (topic_nid, message_offset)
docId := fmt.Sprintf("%d_%d", topicNID, messageOffset)
docId := fmt.Sprintf("%d,%d", topicNID, messageOffset)
cosmosDocId := cosmosdbapi.GetDocumentId(t.DB.cosmosConfig.ContainerName, t.getCollectionNameMessages(), docId)
data := messageCosmos{

View file

@ -149,7 +149,7 @@ func (s *crossSigningKeysStatements) UpsertCrossSigningKeysForUser(
return fmt.Errorf("unknown key purpose %q", keyType)
}
// PRIMARY KEY (user_id, key_type)
docId := fmt.Sprintf("%s_%s", userID, keyType)
docId := fmt.Sprintf("%s,%s", userID, keyType)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, _ := getCrossSigningKeys(s, ctx, s.getPartitionKey(userID), cosmosDocId)

View file

@ -183,7 +183,7 @@ func (s *crossSigningSigsStatements) UpsertCrossSigningSigsForTarget(
// " VALUES($1, $2, $3, $4, $5)"
// PRIMARY KEY (origin_user_id, target_user_id, target_key_id)
docId := fmt.Sprintf("%s_%s_%s", originUserID, targetUserID, targetKeyID)
docId := fmt.Sprintf("%s,%s,%s", originUserID, targetUserID, targetKeyID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, _ := getCrossSigningSigs(s, ctx, s.getPartitionKey(targetUserID), cosmosDocId)

View file

@ -325,7 +325,7 @@ func (s *deviceKeysStatements) SelectDeviceKeysJSON(ctx context.Context, keys []
// err := s.selectDeviceKeysStmt.QueryRowContext(ctx, key.UserID, key.DeviceID).Scan(&keyJSONStr, &streamID, &displayName)
// UNIQUE (user_id, device_id)
docId := fmt.Sprintf("%s_%s", key.UserID, key.DeviceID)
docId := fmt.Sprintf("%s,%s", key.UserID, key.DeviceID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
response, err := getDeviceKey(s, ctx, s.getPartitionKey(key.UserID), cosmosDocId)
@ -437,7 +437,7 @@ func (s *deviceKeysStatements) InsertDeviceKeys(ctx context.Context, txn *sql.Tx
for _, key := range keys {
// UNIQUE (user_id, device_id)
docId := fmt.Sprintf("%s_%s", key.UserID, key.DeviceID)
docId := fmt.Sprintf("%s,%s", key.UserID, key.DeviceID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData := &deviceKeyCosmosData{

View file

@ -120,7 +120,7 @@ func (s *keyChangesStatements) InsertKeyChange(ctx context.Context, partition in
// " DO UPDATE SET user_id = $3"
// UNIQUE (partition, offset)
docId := fmt.Sprintf("%d_%d", partition, offset)
docId := fmt.Sprintf("%d,%d", partition, offset)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, _ := getKeyChangeUser(s, ctx, s.getPartitionKey(), cosmosDocId)

View file

@ -275,7 +275,7 @@ func (s *oneTimeKeysStatements) InsertOneTimeKeys(
algo, keyID := keys.Split(keyIDWithAlgo)
// UNIQUE (user_id, device_id, key_id, algorithm)
docId := fmt.Sprintf("%s_%s_%s_%s", keys.UserID, keys.DeviceID, keyID, algo)
docId := fmt.Sprintf("%s,%s,%s,%s", keys.UserID, keys.DeviceID, keyID, algo)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
data := oneTimeKeyCosmos{

View file

@ -139,7 +139,7 @@ func (s *mediaStatements) insertMedia(
// VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
// CREATE UNIQUE INDEX IF NOT EXISTS mediaapi_media_repository_index ON mediaapi_media_repository (media_id, media_origin);
docId := fmt.Sprintf("%s_%s", mediaMetadata.MediaID, mediaMetadata.Origin)
docId := fmt.Sprintf("%s,%s", mediaMetadata.MediaID, mediaMetadata.Origin)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
data := mediaRepositoryCosmos{
@ -194,7 +194,7 @@ func (s *mediaStatements) selectMedia(
// SELECT content_type, file_size_bytes, creation_ts, upload_name, base64hash, user_id FROM mediaapi_media_repository WHERE media_id = $1 AND media_origin = $2
// CREATE UNIQUE INDEX IF NOT EXISTS mediaapi_media_repository_index ON mediaapi_media_repository (media_id, media_origin);
docId := fmt.Sprintf("%s_%s", mediaMetadata.MediaID, mediaMetadata.Origin)
docId := fmt.Sprintf("%s,%s", mediaMetadata.MediaID, mediaMetadata.Origin)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
// err := s.selectMediaStmt.QueryRowContext(

View file

@ -131,7 +131,7 @@ func (s *thumbnailStatements) insertThumbnail(
// stmt := sqlutil.TxStmt(txn, s.insertThumbnailStmt)
// CREATE UNIQUE INDEX IF NOT EXISTS mediaapi_thumbnail_index ON mediaapi_thumbnail (media_id, media_origin, width, height, resize_method);
docId := fmt.Sprintf("%s_%s_%d_%d_%s",
docId := fmt.Sprintf("%s,%s,%d,%d,%s",
thumbnailMetadata.MediaMetadata.MediaID,
thumbnailMetadata.MediaMetadata.Origin,
thumbnailMetadata.ThumbnailSize.Width,
@ -200,7 +200,7 @@ func (s *thumbnailStatements) selectThumbnail(
// SELECT content_type, file_size_bytes, creation_ts FROM mediaapi_thumbnail WHERE media_id = $1 AND media_origin = $2 AND width = $3 AND height = $4 AND resize_method = $5
// CREATE UNIQUE INDEX IF NOT EXISTS mediaapi_thumbnail_index ON mediaapi_thumbnail (media_id, media_origin, width, height, resize_method);
docId := fmt.Sprintf("%s_%s_%d_%d_%s",
docId := fmt.Sprintf("%s,%s,%d,%d,%s",
mediaID,
mediaOrigin,
width,

View file

@ -268,7 +268,7 @@ func (s *membershipStatements) InsertMembership(
// " ON CONFLICT DO NOTHING"
// UNIQUE (room_nid, target_nid)
docId := fmt.Sprintf("%d_%d", roomNID, targetUserNID)
docId := fmt.Sprintf("%d,%d", roomNID, targetUserNID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
// " ON CONFLICT DO NOTHING"
@ -317,7 +317,7 @@ func (s *membershipStatements) SelectMembershipForUpdate(
// "SELECT membership_nid FROM roomserver_membership" +
// " WHERE room_nid = $1 AND target_nid = $2"
docId := fmt.Sprintf("%d_%d", roomNID, targetUserNID)
docId := fmt.Sprintf("%d,%d", roomNID, targetUserNID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
response, err := getMembership(s, ctx, s.getPartitionKey(), cosmosDocId)
@ -335,7 +335,7 @@ func (s *membershipStatements) SelectMembershipFromRoomAndTarget(
// "SELECT membership_nid, event_nid, forgotten FROM roomserver_membership" +
// " WHERE room_nid = $1 AND target_nid = $2"
docId := fmt.Sprintf("%d_%d", roomNID, targetUserNID)
docId := fmt.Sprintf("%d,%d", roomNID, targetUserNID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
response, err := getMembership(s, ctx, s.getPartitionKey(), cosmosDocId)
if response != nil {
@ -432,7 +432,7 @@ func (s *membershipStatements) UpdateMembership(
// "UPDATE roomserver_membership SET sender_nid = $1, membership_nid = $2, event_nid = $3, forgotten = $4" +
// " WHERE room_nid = $5 AND target_nid = $6"
docId := fmt.Sprintf("%d_%d", roomNID, targetUserNID)
docId := fmt.Sprintf("%d,%d", roomNID, targetUserNID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, err := getMembership(s, ctx, s.getPartitionKey(), cosmosDocId)
@ -693,7 +693,7 @@ func (s *membershipStatements) UpdateForgetMembership(
// "UPDATE roomserver_membership SET forgotten = $1" +
// " WHERE room_nid = $2 AND target_nid = $3"
docId := fmt.Sprintf("%d_%d", roomNID, targetUserNID)
docId := fmt.Sprintf("%d,%d", roomNID, targetUserNID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, err := getMembership(s, ctx, s.getPartitionKey(), cosmosDocId)

View file

@ -18,7 +18,7 @@ package cosmosdb
import (
"context"
"database/sql"
"encoding/hex"
"encoding/base64"
"fmt"
"sort"
@ -144,7 +144,7 @@ func (s *stateBlockStatements) BulkInsertStateData(
// ).Scan(&id)
// state_block_hash BLOB UNIQUE,
docId := hex.EncodeToString(nids.Hash())
docId := base64.StdEncoding.EncodeToString(nids.Hash())
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
//See if it exists

View file

@ -68,9 +68,8 @@ func (s *transactionStatements) getCollectionName() string {
return cosmosdbapi.GetCollectionName(s.db.databaseName, s.tableName)
}
func (s *transactionStatements) getPartitionKey(transactionID string) string {
uniqueId := transactionID
return cosmosdbapi.GetPartitionKeyByUniqueId(s.db.cosmosConfig.TenantName, s.getCollectionName(), uniqueId)
func (s *transactionStatements) getPartitionKey() string {
return cosmosdbapi.GetPartitionKeyByCollection(s.db.cosmosConfig.TenantName, s.getCollectionName())
}
func getTransaction(s *transactionStatements, ctx context.Context, pk string, docId string) (*transactionCosmosData, error) {
@ -114,7 +113,7 @@ func (s *transactionStatements) InsertTransaction(
// VALUES ($1, $2, $3, $4)
// PRIMARY KEY (transaction_id, session_id, user_id)
docId := fmt.Sprintf("%s_%d_%s", transactionID, sessionID, userID)
docId := fmt.Sprintf("%s,%d,%s", transactionID, sessionID, userID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
data := transactionCosmos{
@ -125,7 +124,7 @@ func (s *transactionStatements) InsertTransaction(
}
var dbData = transactionCosmosData{
CosmosDocument: cosmosdbapi.GenerateDocument(s.getCollectionName(), s.db.cosmosConfig.TenantName, s.getPartitionKey(transactionID), cosmosDocId),
CosmosDocument: cosmosdbapi.GenerateDocument(s.getCollectionName(), s.db.cosmosConfig.TenantName, s.getPartitionKey(), cosmosDocId),
Transaction: data,
}
@ -151,10 +150,10 @@ func (s *transactionStatements) SelectTransactionEventID(
// WHERE transaction_id = $1 AND session_id = $2 AND user_id = $3
// PRIMARY KEY (transaction_id, session_id, user_id)
docId := fmt.Sprintf("%s_%d_%s", transactionID, sessionID, userID)
docId := fmt.Sprintf("%s,%d,%s", transactionID, sessionID, userID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
response, err := getTransaction(s, ctx, s.getPartitionKey(transactionID), cosmosDocId)
response, err := getTransaction(s, ctx, s.getPartitionKey(), cosmosDocId)
if err != nil {
return "", err

View file

@ -204,7 +204,7 @@ func (s *serverKeyStatements) upsertServerKeys(
// stmt := sqlutil.TxStmt(txn, s.upsertServerKeysStmt)
// UNIQUE (server_name, server_key_id)
docId := fmt.Sprintf("%s_%s", string(request.ServerName), string(request.KeyID))
docId := fmt.Sprintf("%s,%s", string(request.ServerName), string(request.KeyID))
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, _ := getServerKey(s, ctx, s.getPartitionKey(), cosmosDocId)

View file

@ -137,7 +137,7 @@ func (s *accountDataStatements) InsertAccountData(
}
// UNIQUE (user_id, room_id, type)
docId := fmt.Sprintf("%s_%s_%s", userID, roomID, dataType)
docId := fmt.Sprintf("%s,%s,%s", userID, roomID, dataType)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, _ := getAccountDataType(s, ctx, s.getPartitionKey(), cosmosDocId)

View file

@ -141,7 +141,7 @@ func (s *backwardExtremitiesStatements) InsertsBackwardExtremity(
// _, err = sqlutil.TxStmt(txn, s.insertBackwardExtremityStmt).ExecContext(ctx, roomID, eventID, prevEventID)
// PRIMARY KEY(room_id, event_id, prev_event_id)
docId := fmt.Sprintf("%s_%s_%s", roomID, eventID, prevEventID)
docId := fmt.Sprintf("%s,%s,%s", roomID, eventID, prevEventID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, _ := getBackwardExtremity(s, ctx, s.getPartitionKey(roomID), cosmosDocId)

View file

@ -391,7 +391,7 @@ func (s *currentRoomStateStatements) UpsertRoomState(
// )
// " ON CONFLICT (room_id, type, state_key)" +
docId := fmt.Sprintf("%s_%s_%s", event.RoomID(), event.Type(), *event.StateKey())
docId := fmt.Sprintf("%s,%s,%s", event.RoomID(), event.Type(), *event.StateKey())
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
membershipData := ""
@ -556,7 +556,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, stateKey)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
var response, err = getEvent(s, ctx, s.getPartitionKey(), cosmosDocId)

View file

@ -117,7 +117,7 @@ func (s *filterStatements) SelectFilter(
// err := s.selectFilterStmt.QueryRowContext(ctx, localpart, filterID).Scan(&filterData)
// UNIQUE (id, localpart)
docId := fmt.Sprintf("%s_%s", localpart, filterID)
docId := fmt.Sprintf("%s,%s", localpart, filterID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
var response, err = getFilter(s, ctx, s.getPartitionKey(), cosmosDocId)
@ -208,7 +208,7 @@ func (s *filterStatements) InsertFilter(
}
// UNIQUE (id, localpart)
docId := fmt.Sprintf("%s_%d", localpart, seqID)
docId := fmt.Sprintf("%s,%d", localpart, seqID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
var dbData = filterCosmosData{

View file

@ -146,7 +146,7 @@ func (s *membershipsStatements) UpsertMembership(
// )
// UNIQUE (room_id, user_id, membership)
docId := fmt.Sprintf("%s_%s_%s", event.RoomID(), *event.StateKey(), membership)
docId := fmt.Sprintf("%s,%s,%s", event.RoomID(), *event.StateKey(), membership)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, _ := getMembership(s, ctx, s.getPartitionKey(), cosmosDocId)

View file

@ -192,7 +192,7 @@ func (s *outputRoomEventsTopologyStatements) InsertEventInTopology(
// " ON CONFLICT DO NOTHING"
// UNIQUE(topological_position, room_id, stream_position)
docId := fmt.Sprintf("%d_%s_%d", event.Depth(), event.RoomID(), pos)
docId := fmt.Sprintf("%d,%s,%d", event.Depth(), event.RoomID(), pos)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
var err error

View file

@ -168,7 +168,7 @@ func (s *peekStatements) InsertPeek(
// " VALUES ($1, $2, $3, $4, $5, false)"
// UNIQUE(room_id, user_id, device_id)
docId := fmt.Sprintf("%s_%s_%s", roomID, userID, deviceID)
docId := fmt.Sprintf("%s,%s,%s", roomID, userID, deviceID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
dbData, _ := getPeek(s, ctx, s.getPartitionKey(), cosmosDocId)

View file

@ -120,7 +120,7 @@ func (r *receiptStatements) UpsertReceipt(ctx context.Context, txn *sql.Tx, room
// " DO UPDATE SET id = $7, event_id = $8, receipt_ts = $9"
// CONSTRAINT syncapi_receipts_unique UNIQUE (room_id, receipt_type, user_id)
docId := fmt.Sprintf("%s_%s_%s", roomId, receiptType, userId)
docId := fmt.Sprintf("%s,%s,%s", roomId, receiptType, userId)
cosmosDocId := cosmosdbapi.GetDocumentId(r.db.cosmosConfig.ContainerName, r.getCollectionName(), docId)
data := receiptCosmos{

View file

@ -100,9 +100,9 @@ func (s *accountDataStatements) insertAccountData(
// ON CONFLICT (localpart, room_id, type) DO UPDATE SET content = $4
id := ""
if roomID == "" {
id = fmt.Sprintf("%s_%s", localpart, dataType)
id = fmt.Sprintf("%s,%s", localpart, dataType)
} else {
id = fmt.Sprintf("%s_%s_%s", localpart, roomID, dataType)
id = fmt.Sprintf("%s,%s,%s", localpart, roomID, dataType)
}
docId := id

View file

@ -188,7 +188,7 @@ func (s *keyBackupStatements) insertBackupKey(
// ctx, userID, key.RoomID, key.SessionID, version, key.FirstMessageIndex, key.ForwardedCount, key.IsVerified, string(key.SessionData),
// )
// CREATE UNIQUE INDEX IF NOT EXISTS e2e_room_keys_idx ON account_e2e_room_keys(user_id, room_id, session_id, version);
docId := fmt.Sprintf("%s_%s_%s_%s", userID, key.RoomID, key.SessionID, version)
docId := fmt.Sprintf("%s,%s,%s,%s", userID, key.RoomID, key.SessionID, version)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
data := keyBackupCosmos{
@ -228,7 +228,7 @@ func (s *keyBackupStatements) updateBackupKey(
// )
// CREATE UNIQUE INDEX IF NOT EXISTS e2e_room_keys_idx ON account_e2e_room_keys(user_id, room_id, session_id, version);
docId := fmt.Sprintf("%s_%s_%s_%s", userID, key.RoomID, key.SessionID, version)
docId := fmt.Sprintf("%s,%s,%s,%s", userID, key.RoomID, key.SessionID, version)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
item, err := getKeyBackup(s, ctx, s.getPartitionKey(userID), cosmosDocId)

View file

@ -144,7 +144,7 @@ func (s *keyBackupVersionStatements) insertKeyBackup(
}
// err = txn.Stmt(s.insertKeyBackupStmt).QueryRowContext(ctx, userID, algorithm, string(authData), etag).Scan(&versionInt)
// CREATE UNIQUE INDEX IF NOT EXISTS account_e2e_room_keys_versions_idx ON account_e2e_room_keys_versions(user_id, version);
docId := fmt.Sprintf("%s_%d", userID, versionInt)
docId := fmt.Sprintf("%s,%d", userID, versionInt)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
data := keyBackupVersionCosmos{
@ -181,7 +181,7 @@ func (s *keyBackupVersionStatements) updateKeyBackupAuthData(
return fmt.Errorf("invalid version")
}
// CREATE UNIQUE INDEX IF NOT EXISTS account_e2e_room_keys_versions_idx ON account_e2e_room_keys_versions(user_id, version);
docId := fmt.Sprintf("%s_%d", userID, versionInt)
docId := fmt.Sprintf("%s,%d", userID, versionInt)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
item, err := getKeyBackupVersion(s, ctx, s.getPartitionKey(userID), cosmosDocId)
@ -212,7 +212,7 @@ func (s *keyBackupVersionStatements) updateKeyBackupETag(
return fmt.Errorf("invalid version")
}
// CREATE UNIQUE INDEX IF NOT EXISTS account_e2e_room_keys_versions_idx ON account_e2e_room_keys_versions(user_id, version);
docId := fmt.Sprintf("%s_%d", userID, versionInt)
docId := fmt.Sprintf("%s,%d", userID, versionInt)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
item, err := getKeyBackupVersion(s, ctx, s.getPartitionKey(userID), cosmosDocId)
@ -243,7 +243,7 @@ func (s *keyBackupVersionStatements) deleteKeyBackup(
return false, fmt.Errorf("invalid version")
}
// CREATE UNIQUE INDEX IF NOT EXISTS account_e2e_room_keys_versions_idx ON account_e2e_room_keys_versions(user_id, version);
docId := fmt.Sprintf("%s_%d", userID, versionInt)
docId := fmt.Sprintf("%s,%d", userID, versionInt)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
item, err := getKeyBackupVersion(s, ctx, s.getPartitionKey(userID), cosmosDocId)
@ -313,7 +313,7 @@ func (s *keyBackupVersionStatements) selectKeyBackup(
return
}
// CREATE UNIQUE INDEX IF NOT EXISTS account_e2e_room_keys_versions_idx ON account_e2e_room_keys_versions(user_id, version);
docId := fmt.Sprintf("%s_%d", userID, versionInt)
docId := fmt.Sprintf("%s,%d", userID, versionInt)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
res, err := getKeyBackupVersion(s, ctx, s.getPartitionKey(userID), cosmosDocId)

View file

@ -146,7 +146,7 @@ func (s *threepidStatements) insertThreePID(
ThreePID: threepid,
}
docId := fmt.Sprintf("%s_%s", threepid, medium)
docId := fmt.Sprintf("%s,%s", threepid, medium)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
var dbData = threePIDCosmosData{
CosmosDocument: cosmosdbapi.GenerateDocument(s.getCollectionName(), s.db.cosmosConfig.TenantName, s.getPartitionKey(), cosmosDocId),
@ -171,7 +171,7 @@ func (s *threepidStatements) deleteThreePID(
ctx context.Context, threepid string, medium string) (err error) {
// "DELETE FROM account_threepid WHERE threepid = $1 AND medium = $2"
docId := fmt.Sprintf("%s_%s", threepid, medium)
docId := fmt.Sprintf("%s,%s", threepid, medium)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
var options = cosmosdbapi.GetDeleteDocumentOptions(s.getPartitionKey())
_, err = cosmosdbapi.GetClient(s.db.connection).DeleteDocument(

View file

@ -188,7 +188,7 @@ func (s *devicesStatements) insertDevice(
// access_token TEXT PRIMARY KEY,
// UNIQUE (localpart, device_id)
// HACK: check for duplicate PK as we are using the UNIQUE key for the DocId
docId := fmt.Sprintf("%s_%s", localpart, id)
docId := fmt.Sprintf("%s,%s", localpart, id)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
data := deviceCosmos{
@ -227,7 +227,7 @@ func (s *devicesStatements) deleteDevice(
ctx context.Context, id, localpart string,
) error {
// "DELETE FROM device_devices WHERE device_id = $1 AND localpart = $2"
docId := fmt.Sprintf("%s_%s", localpart, id)
docId := fmt.Sprintf("%s,%s", localpart, id)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
var options = cosmosdbapi.GetDeleteDocumentOptions(s.getPartitionKey())
var _, err = cosmosdbapi.GetClient(s.db.connection).DeleteDocument(
@ -301,7 +301,7 @@ func (s *devicesStatements) updateDeviceName(
ctx context.Context, localpart, deviceID string, displayName *string,
) error {
// "UPDATE device_devices SET display_name = $1 WHERE localpart = $2 AND device_id = $3"
docId := fmt.Sprintf("%s_%s", localpart, deviceID)
docId := fmt.Sprintf("%s,%s", localpart, deviceID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
var item, exGet = getDevice(s, ctx, s.getPartitionKey(), cosmosDocId)
if exGet != nil {
@ -354,7 +354,7 @@ func (s *devicesStatements) selectDeviceByID(
ctx context.Context, localpart, deviceID string,
) (*api.Device, error) {
// "SELECT display_name FROM device_devices WHERE localpart = $1 and device_id = $2"
docId := fmt.Sprintf("%s_%s", localpart, deviceID)
docId := fmt.Sprintf("%s,%s", localpart, deviceID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
var response, exGet = getDevice(s, ctx, s.getPartitionKey(), cosmosDocId)
if exGet != nil {
@ -422,7 +422,7 @@ func (s *devicesStatements) updateDeviceLastSeen(ctx context.Context, localpart,
lastSeenTs := time.Now().UnixNano() / 1000000
// "UPDATE device_devices SET last_seen_ts = $1, ip = $2 WHERE localpart = $3 AND device_id = $4"
docId := fmt.Sprintf("%s_%s", localpart, deviceID)
docId := fmt.Sprintf("%s,%s", localpart, deviceID)
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, s.getCollectionName(), docId)
var item, exGet = getDevice(s, ctx, s.getPartitionKey(), cosmosDocId)
if exGet != nil {