diff --git a/federationsender/storage/cosmosdb/inbound_peeks_table.go b/federationsender/storage/cosmosdb/inbound_peeks_table.go index da9c8d095..6775cc1f5 100644 --- a/federationsender/storage/cosmosdb/inbound_peeks_table.go +++ b/federationsender/storage/cosmosdb/inbound_peeks_table.go @@ -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) diff --git a/federationsender/storage/cosmosdb/outbound_peeks_table.go b/federationsender/storage/cosmosdb/outbound_peeks_table.go index cf9ec1830..8b39a6c5c 100644 --- a/federationsender/storage/cosmosdb/outbound_peeks_table.go +++ b/federationsender/storage/cosmosdb/outbound_peeks_table.go @@ -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) diff --git a/federationsender/storage/cosmosdb/queue_edus_table.go b/federationsender/storage/cosmosdb/queue_edus_table.go index f08ee65bb..039fe8cee 100644 --- a/federationsender/storage/cosmosdb/queue_edus_table.go +++ b/federationsender/storage/cosmosdb/queue_edus_table.go @@ -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{ diff --git a/federationsender/storage/cosmosdb/queue_pdus_table.go b/federationsender/storage/cosmosdb/queue_pdus_table.go index 99e679c6e..7edcc1e99 100644 --- a/federationsender/storage/cosmosdb/queue_pdus_table.go +++ b/federationsender/storage/cosmosdb/queue_pdus_table.go @@ -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{ diff --git a/internal/cosmosdbutil/partition_offset_table.go b/internal/cosmosdbutil/partition_offset_table.go index cb206ae60..9d8e46b25 100644 --- a/internal/cosmosdbutil/partition_offset_table.go +++ b/internal/cosmosdbutil/partition_offset_table.go @@ -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) diff --git a/internal/naffka/naffkacosmosdb/naffka_topics_table.go b/internal/naffka/naffkacosmosdb/naffka_topics_table.go index 2e123e6ea..924ba2be7 100644 --- a/internal/naffka/naffkacosmosdb/naffka_topics_table.go +++ b/internal/naffka/naffkacosmosdb/naffka_topics_table.go @@ -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{ diff --git a/keyserver/storage/cosmosdb/cross_signing_keys_table.go b/keyserver/storage/cosmosdb/cross_signing_keys_table.go index f654bde64..99a5f6603 100644 --- a/keyserver/storage/cosmosdb/cross_signing_keys_table.go +++ b/keyserver/storage/cosmosdb/cross_signing_keys_table.go @@ -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) diff --git a/keyserver/storage/cosmosdb/cross_signing_sigs_table.go b/keyserver/storage/cosmosdb/cross_signing_sigs_table.go index 30037d830..4763424a7 100644 --- a/keyserver/storage/cosmosdb/cross_signing_sigs_table.go +++ b/keyserver/storage/cosmosdb/cross_signing_sigs_table.go @@ -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) diff --git a/keyserver/storage/cosmosdb/device_keys_table.go b/keyserver/storage/cosmosdb/device_keys_table.go index d18023262..67bd6424d 100644 --- a/keyserver/storage/cosmosdb/device_keys_table.go +++ b/keyserver/storage/cosmosdb/device_keys_table.go @@ -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{ diff --git a/keyserver/storage/cosmosdb/key_changes_table.go b/keyserver/storage/cosmosdb/key_changes_table.go index 72e81174b..86ced845c 100644 --- a/keyserver/storage/cosmosdb/key_changes_table.go +++ b/keyserver/storage/cosmosdb/key_changes_table.go @@ -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) diff --git a/keyserver/storage/cosmosdb/one_time_keys_table.go b/keyserver/storage/cosmosdb/one_time_keys_table.go index a3972e070..15e6e681a 100644 --- a/keyserver/storage/cosmosdb/one_time_keys_table.go +++ b/keyserver/storage/cosmosdb/one_time_keys_table.go @@ -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{ diff --git a/mediaapi/storage/cosmosdb/media_repository_table.go b/mediaapi/storage/cosmosdb/media_repository_table.go index 63622269b..b7e30edb1 100644 --- a/mediaapi/storage/cosmosdb/media_repository_table.go +++ b/mediaapi/storage/cosmosdb/media_repository_table.go @@ -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( diff --git a/mediaapi/storage/cosmosdb/thumbnail_table.go b/mediaapi/storage/cosmosdb/thumbnail_table.go index a2cea0f6b..426680b9e 100644 --- a/mediaapi/storage/cosmosdb/thumbnail_table.go +++ b/mediaapi/storage/cosmosdb/thumbnail_table.go @@ -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, diff --git a/roomserver/storage/cosmosdb/membership_table.go b/roomserver/storage/cosmosdb/membership_table.go index a2c415f61..2c1f677fe 100644 --- a/roomserver/storage/cosmosdb/membership_table.go +++ b/roomserver/storage/cosmosdb/membership_table.go @@ -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) diff --git a/roomserver/storage/cosmosdb/state_block_table.go b/roomserver/storage/cosmosdb/state_block_table.go index 5b898db93..997ef1835 100644 --- a/roomserver/storage/cosmosdb/state_block_table.go +++ b/roomserver/storage/cosmosdb/state_block_table.go @@ -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 diff --git a/roomserver/storage/cosmosdb/transactions_table.go b/roomserver/storage/cosmosdb/transactions_table.go index c245ffa20..ba86c0578 100644 --- a/roomserver/storage/cosmosdb/transactions_table.go +++ b/roomserver/storage/cosmosdb/transactions_table.go @@ -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 diff --git a/signingkeyserver/storage/cosmosdb/server_key_table.go b/signingkeyserver/storage/cosmosdb/server_key_table.go index 6a10a8c3b..d037d9175 100644 --- a/signingkeyserver/storage/cosmosdb/server_key_table.go +++ b/signingkeyserver/storage/cosmosdb/server_key_table.go @@ -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) diff --git a/syncapi/storage/cosmosdb/account_data_table.go b/syncapi/storage/cosmosdb/account_data_table.go index bad466016..3637a4ce0 100644 --- a/syncapi/storage/cosmosdb/account_data_table.go +++ b/syncapi/storage/cosmosdb/account_data_table.go @@ -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) diff --git a/syncapi/storage/cosmosdb/backwards_extremities_table.go b/syncapi/storage/cosmosdb/backwards_extremities_table.go index d19c20427..a518391d9 100644 --- a/syncapi/storage/cosmosdb/backwards_extremities_table.go +++ b/syncapi/storage/cosmosdb/backwards_extremities_table.go @@ -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) diff --git a/syncapi/storage/cosmosdb/current_room_state_table.go b/syncapi/storage/cosmosdb/current_room_state_table.go index db14c8edb..2b5d8c04e 100644 --- a/syncapi/storage/cosmosdb/current_room_state_table.go +++ b/syncapi/storage/cosmosdb/current_room_state_table.go @@ -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) diff --git a/syncapi/storage/cosmosdb/filter_table.go b/syncapi/storage/cosmosdb/filter_table.go index c6bb154dc..6b94b275e 100644 --- a/syncapi/storage/cosmosdb/filter_table.go +++ b/syncapi/storage/cosmosdb/filter_table.go @@ -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{ diff --git a/syncapi/storage/cosmosdb/memberships_table.go b/syncapi/storage/cosmosdb/memberships_table.go index 7c3560757..913f4a62e 100644 --- a/syncapi/storage/cosmosdb/memberships_table.go +++ b/syncapi/storage/cosmosdb/memberships_table.go @@ -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) diff --git a/syncapi/storage/cosmosdb/output_room_events_topology_table.go b/syncapi/storage/cosmosdb/output_room_events_topology_table.go index 6e9f45d6f..e50d01da9 100644 --- a/syncapi/storage/cosmosdb/output_room_events_topology_table.go +++ b/syncapi/storage/cosmosdb/output_room_events_topology_table.go @@ -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 diff --git a/syncapi/storage/cosmosdb/peeks_table.go b/syncapi/storage/cosmosdb/peeks_table.go index e904f0426..6795e08d3 100644 --- a/syncapi/storage/cosmosdb/peeks_table.go +++ b/syncapi/storage/cosmosdb/peeks_table.go @@ -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) diff --git a/syncapi/storage/cosmosdb/receipt_table.go b/syncapi/storage/cosmosdb/receipt_table.go index b16970461..90affd3c1 100644 --- a/syncapi/storage/cosmosdb/receipt_table.go +++ b/syncapi/storage/cosmosdb/receipt_table.go @@ -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{ diff --git a/userapi/storage/accounts/cosmosdb/account_data_table.go b/userapi/storage/accounts/cosmosdb/account_data_table.go index 898dbc777..d18732c2e 100644 --- a/userapi/storage/accounts/cosmosdb/account_data_table.go +++ b/userapi/storage/accounts/cosmosdb/account_data_table.go @@ -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 diff --git a/userapi/storage/accounts/cosmosdb/key_backup_table.go b/userapi/storage/accounts/cosmosdb/key_backup_table.go index adc9b0456..00f4746ef 100644 --- a/userapi/storage/accounts/cosmosdb/key_backup_table.go +++ b/userapi/storage/accounts/cosmosdb/key_backup_table.go @@ -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) diff --git a/userapi/storage/accounts/cosmosdb/key_backup_version_table.go b/userapi/storage/accounts/cosmosdb/key_backup_version_table.go index 20d66cd33..9ed269c8c 100644 --- a/userapi/storage/accounts/cosmosdb/key_backup_version_table.go +++ b/userapi/storage/accounts/cosmosdb/key_backup_version_table.go @@ -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) diff --git a/userapi/storage/accounts/cosmosdb/threepid_table.go b/userapi/storage/accounts/cosmosdb/threepid_table.go index 2eb18c3b6..6fa06c50f 100644 --- a/userapi/storage/accounts/cosmosdb/threepid_table.go +++ b/userapi/storage/accounts/cosmosdb/threepid_table.go @@ -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( diff --git a/userapi/storage/devices/cosmosdb/devices_table.go b/userapi/storage/devices/cosmosdb/devices_table.go index aed388b75..15f8f3b35 100644 --- a/userapi/storage/devices/cosmosdb/devices_table.go +++ b/userapi/storage/devices/cosmosdb/devices_table.go @@ -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 {