mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 11:23:11 -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
|
||||
func queryVariadic(count int) string {
|
||||
return queryVariadicOffset(count, 0)
|
||||
}
|
||||
|
||||
func queryVariadicOffset(count, offset int) string {
|
||||
str := "("
|
||||
for i := 1; i <= count; i++ {
|
||||
str += fmt.Sprintf("$%d", i)
|
||||
if i < count {
|
||||
for i := 0; i < count; i++ {
|
||||
str += fmt.Sprintf("$%d", i+offset+1)
|
||||
if i < (count - 1) {
|
||||
str += ", "
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,12 +204,25 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries(
|
|||
sort.Sort(tuples)
|
||||
|
||||
eventTypeNIDArray, eventStateKeyNIDArray := tuples.typesAndStateKeysAsArrays()
|
||||
selectStmt := common.TxStmt(txn, s.bulkSelectFilteredStateBlockEntriesStmt)
|
||||
rows, err := selectStmt.QueryContext(
|
||||
sqlStatement := strings.Replace(bulkSelectFilteredStateBlockEntriesSQL, "($1)", queryVariadic(len(stateBlockNIDs)), 1)
|
||||
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,
|
||||
stateBlockNIDsAsArray(stateBlockNIDs),
|
||||
eventTypeNIDArray,
|
||||
sqliteIn(eventStateKeyNIDArray),
|
||||
sqlStatement,
|
||||
params...,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println("bulkSelectFilteredStateBlockEntries s.bulkSelectFilteredStateBlockEntriesStmt.QueryContext:", err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue