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"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/common"
|
"github.com/matrix-org/dendrite/common"
|
||||||
|
|
@ -44,9 +43,9 @@ func Open(dataSourceName string) (*Database, error) {
|
||||||
}
|
}
|
||||||
var cs string
|
var cs string
|
||||||
if uri.Opaque != "" { // file:filename.db
|
if uri.Opaque != "" { // file:filename.db
|
||||||
cs = fmt.Sprintf("%s", uri.Opaque)
|
cs = uri.Opaque
|
||||||
} else if uri.Path != "" { // file:///path/to/filename.db
|
} else if uri.Path != "" { // file:///path/to/filename.db
|
||||||
cs = fmt.Sprintf("%s", uri.Path)
|
cs = uri.Path
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("no filename or path in connect string")
|
return nil, errors.New("no filename or path in connect string")
|
||||||
}
|
}
|
||||||
|
|
@ -286,7 +285,7 @@ func (d *Database) AddState(
|
||||||
) (stateNID types.StateSnapshotNID, err error) {
|
) (stateNID types.StateSnapshotNID, err error) {
|
||||||
err = common.WithTransaction(d.db, func(txn *sql.Tx) error {
|
err = common.WithTransaction(d.db, func(txn *sql.Tx) error {
|
||||||
if len(state) > 0 {
|
if len(state) > 0 {
|
||||||
stateBlockNID, err := d.statements.selectNextStateBlockNID(ctx, txn)
|
stateBlockNID, err = d.statements.selectNextStateBlockNID(ctx, txn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -368,7 +368,7 @@ func (s *outputRoomEventsStatements) selectEvents(
|
||||||
if streamEvents, err := rowsToStreamEvents(rows); err == nil {
|
if streamEvents, err := rowsToStreamEvents(rows); err == nil {
|
||||||
returnEvents = append(returnEvents, streamEvents...)
|
returnEvents = append(returnEvents, streamEvents...)
|
||||||
}
|
}
|
||||||
rows.Close()
|
rows.Close() // nolint: errcheck
|
||||||
}
|
}
|
||||||
return returnEvents, nil
|
return returnEvents, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ type SyncServerDatasource struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSyncServerDatasource creates a new sync server database
|
// NewSyncServerDatasource creates a new sync server database
|
||||||
|
// nolint: gocyclo
|
||||||
func NewSyncServerDatasource(dataSourceName string) (*SyncServerDatasource, error) {
|
func NewSyncServerDatasource(dataSourceName string) (*SyncServerDatasource, error) {
|
||||||
var d SyncServerDatasource
|
var d SyncServerDatasource
|
||||||
uri, err := url.Parse(dataSourceName)
|
uri, err := url.Parse(dataSourceName)
|
||||||
|
|
@ -72,45 +73,50 @@ func NewSyncServerDatasource(dataSourceName string) (*SyncServerDatasource, erro
|
||||||
}
|
}
|
||||||
var cs string
|
var cs string
|
||||||
if uri.Opaque != "" { // file:filename.db
|
if uri.Opaque != "" { // file:filename.db
|
||||||
// cs = fmt.Sprintf("%s?cache=shared&_busy_timeout=9999999", uri.Opaque)
|
cs = uri.Opaque
|
||||||
cs = fmt.Sprintf("%s", uri.Opaque)
|
|
||||||
} else if uri.Path != "" { // file:///path/to/filename.db
|
} else if uri.Path != "" { // file:///path/to/filename.db
|
||||||
// cs = fmt.Sprintf("%s?cache=shared&_busy_timeout=9999999", uri.Path)
|
cs = uri.Path
|
||||||
cs = fmt.Sprintf("%s", uri.Path)
|
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("no filename or path in connect string")
|
return nil, errors.New("no filename or path in connect string")
|
||||||
}
|
}
|
||||||
if d.db, err = sql.Open("sqlite3", cs); err != nil {
|
if d.db, err = sql.Open("sqlite3", cs); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = d.PartitionOffsetStatements.Prepare(d.db, "syncapi"); err != nil {
|
if err = d.prepare(); 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 {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
d.typingCache = cache.NewTypingCache()
|
d.typingCache = cache.NewTypingCache()
|
||||||
return &d, nil
|
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.
|
// 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) {
|
func (d *SyncServerDatasource) AllJoinedUsersInRooms(ctx context.Context) (map[string][]string, error) {
|
||||||
return d.roomstate.selectJoinedUsers(ctx)
|
return d.roomstate.selectJoinedUsers(ctx)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue