mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-18 04:13:10 -06:00
Support sending messages
This commit is contained in:
parent
3a79ea983c
commit
648f05c204
|
|
@ -62,10 +62,14 @@ func (s *statements) prepare(db *sql.DB) error {
|
||||||
|
|
||||||
// Hack of the century
|
// Hack of the century
|
||||||
func queryVariadic(count int) string {
|
func queryVariadic(count int) string {
|
||||||
|
return queryVariadicOffset(count, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func queryVariadicOffset(count, offset int) string {
|
||||||
str := "("
|
str := "("
|
||||||
for i := 1; i <= count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
str += fmt.Sprintf("$%d", i)
|
str += fmt.Sprintf("$%d", i+offset+1)
|
||||||
if i < count {
|
if i < (count - 1) {
|
||||||
str += ", "
|
str += ", "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -204,12 +204,25 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries(
|
||||||
sort.Sort(tuples)
|
sort.Sort(tuples)
|
||||||
|
|
||||||
eventTypeNIDArray, eventStateKeyNIDArray := tuples.typesAndStateKeysAsArrays()
|
eventTypeNIDArray, eventStateKeyNIDArray := tuples.typesAndStateKeysAsArrays()
|
||||||
selectStmt := common.TxStmt(txn, s.bulkSelectFilteredStateBlockEntriesStmt)
|
sqlStatement := strings.Replace(bulkSelectFilteredStateBlockEntriesSQL, "($1)", queryVariadic(len(stateBlockNIDs)), 1)
|
||||||
rows, err := selectStmt.QueryContext(
|
sqlStatement = strings.Replace(sqlStatement, "($2)", queryVariadicOffset(len(eventTypeNIDArray), len(stateBlockNIDs)), 1)
|
||||||
|
sqlStatement = strings.Replace(sqlStatement, "($3)", queryVariadicOffset(len(eventStateKeyNIDArray), len(stateBlockNIDs)+len(eventTypeNIDArray)), 1)
|
||||||
|
|
||||||
|
var params []interface{}
|
||||||
|
for _, val := range stateBlockNIDs {
|
||||||
|
params = append(params, int64(val))
|
||||||
|
}
|
||||||
|
for _, val := range eventTypeNIDArray {
|
||||||
|
params = append(params, val)
|
||||||
|
}
|
||||||
|
for _, val := range eventStateKeyNIDArray {
|
||||||
|
params = append(params, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
rows, err := s.db.QueryContext(
|
||||||
ctx,
|
ctx,
|
||||||
stateBlockNIDsAsArray(stateBlockNIDs),
|
sqlStatement,
|
||||||
eventTypeNIDArray,
|
params...,
|
||||||
sqliteIn(eventStateKeyNIDArray),
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("bulkSelectFilteredStateBlockEntries s.bulkSelectFilteredStateBlockEntriesStmt.QueryContext:", err)
|
fmt.Println("bulkSelectFilteredStateBlockEntries s.bulkSelectFilteredStateBlockEntriesStmt.QueryContext:", err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue