aboutsummaryrefslogtreecommitdiff
path: root/userapi/storage
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2023-11-09 08:42:33 +0100
committerGitHub <noreply@github.com>2023-11-09 08:42:33 +0100
commit699f5ca8c1f73ff7e4b70f0f9273ffcb1c195cdc (patch)
tree924223527aadefe03cceb4f2736ac00b80dcb68b /userapi/storage
parentee73a90aea8349e2695ce555ac868bbf45c11d02 (diff)
More `rows.Close()` and `rows.Err()` (#3262)
Looks like we missed some `rows.Close()` Even though `rows.Err()` is mostly not necessary, we should be more consistent in the DB layer. [skip ci]
Diffstat (limited to 'userapi/storage')
-rw-r--r--userapi/storage/postgres/cross_signing_keys_table.go3
-rw-r--r--userapi/storage/postgres/cross_signing_sigs_table.go3
-rw-r--r--userapi/storage/postgres/key_backup_table.go2
-rw-r--r--userapi/storage/postgres/key_changes_table.go3
-rw-r--r--userapi/storage/postgres/one_time_keys_table.go2
-rw-r--r--userapi/storage/postgres/profile_table.go2
-rw-r--r--userapi/storage/postgres/threepid_table.go4
-rw-r--r--userapi/storage/sqlite3/account_data_table.go4
-rw-r--r--userapi/storage/sqlite3/cross_signing_keys_table.go3
-rw-r--r--userapi/storage/sqlite3/cross_signing_sigs_table.go3
-rw-r--r--userapi/storage/sqlite3/devices_table.go3
-rw-r--r--userapi/storage/sqlite3/key_backup_table.go2
-rw-r--r--userapi/storage/sqlite3/key_changes_table.go3
-rw-r--r--userapi/storage/sqlite3/one_time_keys_table.go2
-rw-r--r--userapi/storage/sqlite3/profile_table.go2
15 files changed, 26 insertions, 15 deletions
diff --git a/userapi/storage/postgres/cross_signing_keys_table.go b/userapi/storage/postgres/cross_signing_keys_table.go
index 138b629d..deb35571 100644
--- a/userapi/storage/postgres/cross_signing_keys_table.go
+++ b/userapi/storage/postgres/cross_signing_keys_table.go
@@ -77,7 +77,7 @@ func (s *crossSigningKeysStatements) SelectCrossSigningKeysForUser(
for rows.Next() {
var keyTypeInt int16
var keyData spec.Base64Bytes
- if err := rows.Scan(&keyTypeInt, &keyData); err != nil {
+ if err = rows.Scan(&keyTypeInt, &keyData); err != nil {
return nil, err
}
keyType, ok := types.KeyTypeIntToPurpose[keyTypeInt]
@@ -86,6 +86,7 @@ func (s *crossSigningKeysStatements) SelectCrossSigningKeysForUser(
}
r[keyType] = keyData
}
+ err = rows.Err()
return
}
diff --git a/userapi/storage/postgres/cross_signing_sigs_table.go b/userapi/storage/postgres/cross_signing_sigs_table.go
index 61a38118..cba015e1 100644
--- a/userapi/storage/postgres/cross_signing_sigs_table.go
+++ b/userapi/storage/postgres/cross_signing_sigs_table.go
@@ -98,7 +98,7 @@ func (s *crossSigningSigsStatements) SelectCrossSigningSigsForTarget(
var userID string
var keyID gomatrixserverlib.KeyID
var signature spec.Base64Bytes
- if err := rows.Scan(&userID, &keyID, &signature); err != nil {
+ if err = rows.Scan(&userID, &keyID, &signature); err != nil {
return nil, err
}
if _, ok := r[userID]; !ok {
@@ -106,6 +106,7 @@ func (s *crossSigningSigsStatements) SelectCrossSigningSigsForTarget(
}
r[userID][keyID] = signature
}
+ err = rows.Err()
return
}
diff --git a/userapi/storage/postgres/key_backup_table.go b/userapi/storage/postgres/key_backup_table.go
index 91a34c35..59944a12 100644
--- a/userapi/storage/postgres/key_backup_table.go
+++ b/userapi/storage/postgres/key_backup_table.go
@@ -162,5 +162,5 @@ func unpackKeys(ctx context.Context, rows *sql.Rows) (map[string]map[string]api.
roomData[key.SessionID] = key.KeyBackupSession
result[key.RoomID] = roomData
}
- return result, nil
+ return result, rows.Err()
}
diff --git a/userapi/storage/postgres/key_changes_table.go b/userapi/storage/postgres/key_changes_table.go
index a0049414..de3a9e9c 100644
--- a/userapi/storage/postgres/key_changes_table.go
+++ b/userapi/storage/postgres/key_changes_table.go
@@ -115,7 +115,7 @@ func (s *keyChangesStatements) SelectKeyChanges(
for rows.Next() {
var userID string
var offset int64
- if err := rows.Scan(&userID, &offset); err != nil {
+ if err = rows.Scan(&userID, &offset); err != nil {
return nil, 0, err
}
if offset > latestOffset {
@@ -123,5 +123,6 @@ func (s *keyChangesStatements) SelectKeyChanges(
}
userIDs = append(userIDs, userID)
}
+ err = rows.Err()
return
}
diff --git a/userapi/storage/postgres/one_time_keys_table.go b/userapi/storage/postgres/one_time_keys_table.go
index 972a5914..a00f4d6f 100644
--- a/userapi/storage/postgres/one_time_keys_table.go
+++ b/userapi/storage/postgres/one_time_keys_table.go
@@ -134,7 +134,7 @@ func (s *oneTimeKeysStatements) CountOneTimeKeys(ctx context.Context, userID, de
}
counts.KeyCount[algorithm] = count
}
- return counts, nil
+ return counts, rows.Err()
}
func (s *oneTimeKeysStatements) InsertOneTimeKeys(ctx context.Context, txn *sql.Tx, keys api.OneTimeKeys) (*api.OneTimeKeysCount, error) {
diff --git a/userapi/storage/postgres/profile_table.go b/userapi/storage/postgres/profile_table.go
index e404c32f..e4f55ed9 100644
--- a/userapi/storage/postgres/profile_table.go
+++ b/userapi/storage/postgres/profile_table.go
@@ -165,5 +165,5 @@ func (s *profilesStatements) SelectProfilesBySearch(
profiles = append(profiles, profile)
}
}
- return profiles, nil
+ return profiles, rows.Err()
}
diff --git a/userapi/storage/postgres/threepid_table.go b/userapi/storage/postgres/threepid_table.go
index 15b42a0a..fc46061d 100644
--- a/userapi/storage/postgres/threepid_table.go
+++ b/userapi/storage/postgres/threepid_table.go
@@ -18,6 +18,7 @@ import (
"context"
"database/sql"
+ "github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/userapi/storage/tables"
"github.com/matrix-org/gomatrixserverlib/spec"
@@ -94,6 +95,7 @@ func (s *threepidStatements) SelectThreePIDsForLocalpart(
if err != nil {
return
}
+ defer internal.CloseAndLogIfError(ctx, rows, "SelectThreePIDsForLocalpart: failed to close rows")
threepids = []authtypes.ThreePID{}
for rows.Next() {
@@ -107,7 +109,7 @@ func (s *threepidStatements) SelectThreePIDsForLocalpart(
Medium: medium,
})
}
-
+ err = rows.Err()
return
}
diff --git a/userapi/storage/sqlite3/account_data_table.go b/userapi/storage/sqlite3/account_data_table.go
index 3a6367c4..240647b3 100644
--- a/userapi/storage/sqlite3/account_data_table.go
+++ b/userapi/storage/sqlite3/account_data_table.go
@@ -19,6 +19,7 @@ import (
"database/sql"
"encoding/json"
+ "github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/userapi/storage/tables"
"github.com/matrix-org/gomatrixserverlib/spec"
@@ -95,6 +96,7 @@ func (s *accountDataStatements) SelectAccountData(
if err != nil {
return nil, nil, err
}
+ defer internal.CloseAndLogIfError(ctx, rows, "SelectAccountData: failed to close rows")
global := map[string]json.RawMessage{}
rooms := map[string]map[string]json.RawMessage{}
@@ -118,7 +120,7 @@ func (s *accountDataStatements) SelectAccountData(
}
}
- return global, rooms, nil
+ return global, rooms, rows.Err()
}
func (s *accountDataStatements) SelectAccountDataByType(
diff --git a/userapi/storage/sqlite3/cross_signing_keys_table.go b/userapi/storage/sqlite3/cross_signing_keys_table.go
index 5c2ce703..65b9ff1a 100644
--- a/userapi/storage/sqlite3/cross_signing_keys_table.go
+++ b/userapi/storage/sqlite3/cross_signing_keys_table.go
@@ -76,7 +76,7 @@ func (s *crossSigningKeysStatements) SelectCrossSigningKeysForUser(
for rows.Next() {
var keyTypeInt int16
var keyData spec.Base64Bytes
- if err := rows.Scan(&keyTypeInt, &keyData); err != nil {
+ if err = rows.Scan(&keyTypeInt, &keyData); err != nil {
return nil, err
}
keyType, ok := types.KeyTypeIntToPurpose[keyTypeInt]
@@ -85,6 +85,7 @@ func (s *crossSigningKeysStatements) SelectCrossSigningKeysForUser(
}
r[keyType] = keyData
}
+ err = rows.Err()
return
}
diff --git a/userapi/storage/sqlite3/cross_signing_sigs_table.go b/userapi/storage/sqlite3/cross_signing_sigs_table.go
index 65726411..bf400a00 100644
--- a/userapi/storage/sqlite3/cross_signing_sigs_table.go
+++ b/userapi/storage/sqlite3/cross_signing_sigs_table.go
@@ -96,7 +96,7 @@ func (s *crossSigningSigsStatements) SelectCrossSigningSigsForTarget(
var userID string
var keyID gomatrixserverlib.KeyID
var signature spec.Base64Bytes
- if err := rows.Scan(&userID, &keyID, &signature); err != nil {
+ if err = rows.Scan(&userID, &keyID, &signature); err != nil {
return nil, err
}
if _, ok := r[userID]; !ok {
@@ -104,6 +104,7 @@ func (s *crossSigningSigsStatements) SelectCrossSigningSigsForTarget(
}
r[userID][keyID] = signature
}
+ err = rows.Err()
return
}
diff --git a/userapi/storage/sqlite3/devices_table.go b/userapi/storage/sqlite3/devices_table.go
index 23e82311..5ce285c8 100644
--- a/userapi/storage/sqlite3/devices_table.go
+++ b/userapi/storage/sqlite3/devices_table.go
@@ -296,6 +296,7 @@ func (s *devicesStatements) SelectDevicesByLocalpart(
if err != nil {
return devices, err
}
+ defer internal.CloseAndLogIfError(ctx, rows, "SelectDevicesByLocalpart: failed to close rows")
var dev api.Device
var lastseents sql.NullInt64
@@ -325,7 +326,7 @@ func (s *devicesStatements) SelectDevicesByLocalpart(
devices = append(devices, dev)
}
- return devices, nil
+ return devices, rows.Err()
}
func (s *devicesStatements) SelectDevicesByID(ctx context.Context, deviceIDs []string) ([]api.Device, error) {
diff --git a/userapi/storage/sqlite3/key_backup_table.go b/userapi/storage/sqlite3/key_backup_table.go
index ed274631..1cdaca18 100644
--- a/userapi/storage/sqlite3/key_backup_table.go
+++ b/userapi/storage/sqlite3/key_backup_table.go
@@ -162,5 +162,5 @@ func unpackKeys(ctx context.Context, rows *sql.Rows) (map[string]map[string]api.
roomData[key.SessionID] = key.KeyBackupSession
result[key.RoomID] = roomData
}
- return result, nil
+ return result, rows.Err()
}
diff --git a/userapi/storage/sqlite3/key_changes_table.go b/userapi/storage/sqlite3/key_changes_table.go
index 923bb57e..7a4898cf 100644
--- a/userapi/storage/sqlite3/key_changes_table.go
+++ b/userapi/storage/sqlite3/key_changes_table.go
@@ -113,7 +113,7 @@ func (s *keyChangesStatements) SelectKeyChanges(
for rows.Next() {
var userID string
var offset int64
- if err := rows.Scan(&userID, &offset); err != nil {
+ if err = rows.Scan(&userID, &offset); err != nil {
return nil, 0, err
}
if offset > latestOffset {
@@ -121,5 +121,6 @@ func (s *keyChangesStatements) SelectKeyChanges(
}
userIDs = append(userIDs, userID)
}
+ err = rows.Err()
return
}
diff --git a/userapi/storage/sqlite3/one_time_keys_table.go b/userapi/storage/sqlite3/one_time_keys_table.go
index a992d399..2a5b1280 100644
--- a/userapi/storage/sqlite3/one_time_keys_table.go
+++ b/userapi/storage/sqlite3/one_time_keys_table.go
@@ -140,7 +140,7 @@ func (s *oneTimeKeysStatements) CountOneTimeKeys(ctx context.Context, userID, de
}
counts.KeyCount[algorithm] = count
}
- return counts, nil
+ return counts, rows.Err()
}
func (s *oneTimeKeysStatements) InsertOneTimeKeys(
diff --git a/userapi/storage/sqlite3/profile_table.go b/userapi/storage/sqlite3/profile_table.go
index a20d7e84..7285110b 100644
--- a/userapi/storage/sqlite3/profile_table.go
+++ b/userapi/storage/sqlite3/profile_table.go
@@ -173,5 +173,5 @@ func (s *profilesStatements) SelectProfilesBySearch(
profiles = append(profiles, profile)
}
}
- return profiles, nil
+ return profiles, rows.Err()
}