mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 11:23:11 -06:00
Fix some linter issues
This commit is contained in:
parent
1d1446253e
commit
2e8138dffd
|
|
@ -19,7 +19,6 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
|
|
@ -44,9 +43,9 @@ func Open(dataSourceName string) (*Database, error) {
|
|||
}
|
||||
var cs string
|
||||
if uri.Opaque != "" { // file:filename.db
|
||||
cs = fmt.Sprintf("%s", uri.Opaque)
|
||||
cs = uri.Opaque
|
||||
} else if uri.Path != "" { // file:///path/to/filename.db
|
||||
cs = fmt.Sprintf("%s", uri.Path)
|
||||
cs = uri.Path
|
||||
} else {
|
||||
return nil, errors.New("no filename or path in connect string")
|
||||
}
|
||||
|
|
@ -286,7 +285,7 @@ func (d *Database) AddState(
|
|||
) (stateNID types.StateSnapshotNID, err error) {
|
||||
err = common.WithTransaction(d.db, func(txn *sql.Tx) error {
|
||||
if len(state) > 0 {
|
||||
stateBlockNID, err := d.statements.selectNextStateBlockNID(ctx, txn)
|
||||
stateBlockNID, err = d.statements.selectNextStateBlockNID(ctx, txn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -368,7 +368,7 @@ func (s *outputRoomEventsStatements) selectEvents(
|
|||
if streamEvents, err := rowsToStreamEvents(rows); err == nil {
|
||||
returnEvents = append(returnEvents, streamEvents...)
|
||||
}
|
||||
rows.Close()
|
||||
rows.Close() // nolint: errcheck
|
||||
}
|
||||
return returnEvents, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ type SyncServerDatasource struct {
|
|||
}
|
||||
|
||||
// NewSyncServerDatasource creates a new sync server database
|
||||
// nolint: gocyclo
|
||||
func NewSyncServerDatasource(dataSourceName string) (*SyncServerDatasource, error) {
|
||||
var d SyncServerDatasource
|
||||
uri, err := url.Parse(dataSourceName)
|
||||
|
|
@ -72,45 +73,50 @@ func NewSyncServerDatasource(dataSourceName string) (*SyncServerDatasource, erro
|
|||
}
|
||||
var cs string
|
||||
if uri.Opaque != "" { // file:filename.db
|
||||
// cs = fmt.Sprintf("%s?cache=shared&_busy_timeout=9999999", uri.Opaque)
|
||||
cs = fmt.Sprintf("%s", uri.Opaque)
|
||||
cs = uri.Opaque
|
||||
} else if uri.Path != "" { // file:///path/to/filename.db
|
||||
// cs = fmt.Sprintf("%s?cache=shared&_busy_timeout=9999999", uri.Path)
|
||||
cs = fmt.Sprintf("%s", uri.Path)
|
||||
cs = uri.Path
|
||||
} else {
|
||||
return nil, errors.New("no filename or path in connect string")
|
||||
}
|
||||
if d.db, err = sql.Open("sqlite3", cs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = d.PartitionOffsetStatements.Prepare(d.db, "syncapi"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = d.streamID.prepare(d.db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = d.accountData.prepare(d.db, &d.streamID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = d.events.prepare(d.db, &d.streamID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := d.roomstate.prepare(d.db, &d.streamID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := d.invites.prepare(d.db, &d.streamID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := d.topology.prepare(d.db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := d.backwardExtremities.prepare(d.db); err != nil {
|
||||
if err = d.prepare(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
d.typingCache = cache.NewTypingCache()
|
||||
return &d, nil
|
||||
}
|
||||
|
||||
func (d *SyncServerDataSource) prepare() error {
|
||||
if err = d.PartitionOffsetStatements.Prepare(d.db, "syncapi"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = d.streamID.prepare(d.db); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = d.accountData.prepare(d.db, &d.streamID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = d.events.prepare(d.db, &d.streamID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.roomstate.prepare(d.db, &d.streamID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.invites.prepare(d.db, &d.streamID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.topology.prepare(d.db); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.backwardExtremities.prepare(d.db); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AllJoinedUsersInRooms returns a map of room ID to a list of all joined user IDs.
|
||||
func (d *SyncServerDatasource) AllJoinedUsersInRooms(ctx context.Context) (map[string][]string, error) {
|
||||
return d.roomstate.selectJoinedUsers(ctx)
|
||||
|
|
|
|||
Loading…
Reference in a new issue