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]
This commit is contained in:
Till 2023-11-09 08:42:33 +01:00 committed by GitHub
parent ee73a90aea
commit 699f5ca8c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 101 additions and 61 deletions

View file

@ -392,7 +392,7 @@ func currentRoomStateRowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, er
})
}
return events, nil
return events, rows.Err()
}
func rowsToEvents(rows *sql.Rows) ([]*rstypes.HeaderedEvent, error) {

View file

@ -19,6 +19,7 @@ import (
"database/sql"
"fmt"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
rstypes "github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/dendrite/syncapi/storage/tables"
@ -160,6 +161,7 @@ func (s *membershipsStatements) SelectMemberships(
if err != nil {
return
}
defer internal.CloseAndLogIfError(ctx, rows, "SelectMemberships: failed to close rows")
var (
eventID string
)

View file

@ -164,7 +164,7 @@ func (s *peekStatements) SelectPeekingDevices(
devices = append(devices, types.PeekingDevice{UserID: userID, DeviceID: deviceID})
result[roomID] = devices
}
return result, nil
return result, rows.Err()
}
func (s *peekStatements) SelectMaxPeekID(

View file

@ -144,7 +144,7 @@ func (p *presenceStatements) GetPresenceForUsers(
presence.ClientFields.Presence = presence.Presence.String()
result = append(result, presence)
}
return result, err
return result, rows.Err()
}
func (p *presenceStatements) GetMaxPresenceID(ctx context.Context, txn *sql.Tx) (pos types.StreamPosition, err error) {

View file

@ -177,7 +177,7 @@ func (s *currentRoomStateStatements) SelectJoinedUsers(
users = append(users, userID)
result[roomID] = users
}
return result, nil
return result, rows.Err()
}
// SelectJoinedUsersInRoom returns a map of room ID to a list of joined user IDs for a given room.
@ -236,7 +236,7 @@ func (s *currentRoomStateStatements) SelectRoomIDsWithMembership(
}
result = append(result, roomID)
}
return result, nil
return result, rows.Err()
}
// SelectRoomIDsWithAnyMembership returns a map of all memberships for the given user.
@ -419,7 +419,7 @@ func currentRoomStateRowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, er
})
}
return events, nil
return events, rows.Err()
}
func rowsToEvents(rows *sql.Rows) ([]*rstypes.HeaderedEvent, error) {

View file

@ -176,7 +176,7 @@ func (s *inviteEventsStatements) SelectInviteEventsInRange(
if lastPos == 0 {
lastPos = r.To
}
return result, retired, lastPos, nil
return result, retired, lastPos, rows.Err()
}
func (s *inviteEventsStatements) SelectMaxInviteID(

View file

@ -19,6 +19,7 @@ import (
"database/sql"
"fmt"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
rstypes "github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/dendrite/syncapi/storage/tables"
@ -163,6 +164,7 @@ func (s *membershipsStatements) SelectMemberships(
if err != nil {
return
}
defer internal.CloseAndLogIfError(ctx, rows, "SelectMemberships: failed to close rows")
var eventID string
for rows.Next() {
if err = rows.Scan(&eventID); err != nil {

View file

@ -274,7 +274,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange(
}
}
return stateNeeded, eventIDToEvent, nil
return stateNeeded, eventIDToEvent, rows.Err()
}
// MaxID returns the ID of the last inserted event in this table. 'txn' is optional. If it is not supplied,
@ -520,7 +520,7 @@ func rowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, error) {
ExcludeFromSync: excludeFromSync,
})
}
return result, nil
return result, rows.Err()
}
func (s *outputRoomEventsStatements) SelectContextEvent(
ctx context.Context, txn *sql.Tx, roomID, eventID string,

View file

@ -18,6 +18,7 @@ import (
"context"
"database/sql"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
rstypes "github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/dendrite/syncapi/storage/tables"
@ -137,6 +138,7 @@ func (s *outputRoomEventsTopologyStatements) SelectEventIDsInRange(
} else if err != nil {
return
}
defer internal.CloseAndLogIfError(ctx, rows, "SelectEventIDsInRange: failed to close rows")
// Return the IDs.
var eventID string
@ -155,7 +157,7 @@ func (s *outputRoomEventsTopologyStatements) SelectEventIDsInRange(
start = tokens[0]
end = tokens[len(tokens)-1]
}
err = rows.Err()
return
}

View file

@ -184,7 +184,7 @@ func (s *peekStatements) SelectPeekingDevices(
devices = append(devices, types.PeekingDevice{UserID: userID, DeviceID: deviceID})
result[roomID] = devices
}
return result, nil
return result, rows.Err()
}
func (s *peekStatements) SelectMaxPeekID(

View file

@ -169,7 +169,7 @@ func (p *presenceStatements) GetPresenceForUsers(
presence.ClientFields.Presence = presence.Presence.String()
result = append(result, presence)
}
return result, err
return result, rows.Err()
}
func (p *presenceStatements) GetMaxPresenceID(ctx context.Context, txn *sql.Tx) (pos types.StreamPosition, err error) {