summaryrefslogtreecommitdiff
path: root/internal/db/bundb
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/bundb')
-rw-r--r--internal/db/bundb/account.go19
-rw-r--r--internal/db/bundb/bundb.go12
-rw-r--r--internal/db/bundb/instance.go3
-rw-r--r--internal/db/bundb/media.go3
-rw-r--r--internal/db/bundb/mention.go3
-rw-r--r--internal/db/bundb/notification.go3
-rw-r--r--internal/db/bundb/relationship.go9
-rw-r--r--internal/db/bundb/session.go2
-rw-r--r--internal/db/bundb/status.go19
-rw-r--r--internal/db/bundb/timeline.go6
10 files changed, 38 insertions, 41 deletions
diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go
index 8d2cea272..9c9dcfc6a 100644
--- a/internal/db/bundb/account.go
+++ b/internal/db/bundb/account.go
@@ -137,8 +137,7 @@ func (a *accountDB) GetInstanceAccount(ctx context.Context, domain string) (*gts
WhereGroup(" AND ", whereEmptyOrNull("domain"))
}
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return nil, a.conn.ProcessError(err)
}
return account, nil
@@ -155,8 +154,7 @@ func (a *accountDB) GetAccountLastPosted(ctx context.Context, accountID string)
Where("account_id = ?", accountID).
Column("created_at")
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return time.Time{}, a.conn.ProcessError(err)
}
return status.CreatedAt, nil
@@ -168,11 +166,12 @@ func (a *accountDB) SetAccountHeaderOrAvatar(ctx context.Context, mediaAttachmen
}
var headerOrAVI string
- if mediaAttachment.Avatar {
+ switch {
+ case mediaAttachment.Avatar:
headerOrAVI = "avatar"
- } else if mediaAttachment.Header {
+ case mediaAttachment.Header:
headerOrAVI = "header"
- } else {
+ default:
return errors.New("given media attachment was neither a header nor an avatar")
}
@@ -202,8 +201,7 @@ func (a *accountDB) GetLocalAccountByUsername(ctx context.Context, username stri
Where("username = ?", username).
WhereGroup(" AND ", whereEmptyOrNull("domain"))
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return nil, a.conn.ProcessError(err)
}
return account, nil
@@ -308,8 +306,7 @@ func (a *accountDB) GetAccountBlocks(ctx context.Context, accountID string, maxI
fq = fq.Limit(limit)
}
- err := fq.Scan(ctx)
- if err != nil {
+ if err := fq.Scan(ctx); err != nil {
return nil, "", "", a.conn.ProcessError(err)
}
diff --git a/internal/db/bundb/bundb.go b/internal/db/bundb/bundb.go
index 033be558f..4634f1981 100644
--- a/internal/db/bundb/bundb.go
+++ b/internal/db/bundb/bundb.go
@@ -54,7 +54,7 @@ const (
dbTypeSqlite = "sqlite"
)
-var registerTables []interface{} = []interface{}{
+var registerTables = []interface{}{
&gtsmodel.StatusToEmoji{},
&gtsmodel.StatusToTag{},
}
@@ -220,7 +220,7 @@ func sqliteConn(ctx context.Context, c *config.Config) (*DBConn, error) {
}
tweakConnectionValues(sqldb)
-
+
if c.DBConfig.Address == "file::memory:?cache=shared" {
logrus.Warn("sqlite in-memory database should only be used for debugging")
// don't close connections on disconnect -- otherwise
@@ -248,11 +248,11 @@ func pgConn(ctx context.Context, c *config.Config) (*DBConn, error) {
if err != nil {
return nil, fmt.Errorf("could not create bundb postgres options: %s", err)
}
-
+
sqldb := stdlib.OpenDB(*opts)
-
+
tweakConnectionValues(sqldb)
-
+
conn := WrapDBConn(bun.NewDB(sqldb, pgdialect.New()))
// ping to check the db is there and listening
@@ -305,6 +305,7 @@ func deriveBunDBPGOptions(c *config.Config) (*pgx.ConnConfig, error) {
case config.DBTLSModeDisable, config.DBTLSModeUnset:
break // nothing to do
case config.DBTLSModeEnable:
+ /* #nosec G402 */
tlsConfig = &tls.Config{
InsecureSkipVerify: true,
}
@@ -312,6 +313,7 @@ func deriveBunDBPGOptions(c *config.Config) (*pgx.ConnConfig, error) {
tlsConfig = &tls.Config{
InsecureSkipVerify: false,
ServerName: c.DBConfig.Address,
+ MinVersion: tls.VersionTLS12,
}
}
diff --git a/internal/db/bundb/instance.go b/internal/db/bundb/instance.go
index ea507ad43..006a76e24 100644
--- a/internal/db/bundb/instance.go
+++ b/internal/db/bundb/instance.go
@@ -116,8 +116,7 @@ func (i *instanceDB) GetInstanceAccounts(ctx context.Context, domain string, max
q = q.Limit(limit)
}
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return nil, i.conn.ProcessError(err)
}
return accounts, nil
diff --git a/internal/db/bundb/media.go b/internal/db/bundb/media.go
index 3c9ee587d..1a06a0260 100644
--- a/internal/db/bundb/media.go
+++ b/internal/db/bundb/media.go
@@ -45,8 +45,7 @@ func (m *mediaDB) GetAttachmentByID(ctx context.Context, id string) (*gtsmodel.M
q := m.newMediaQ(attachment).
Where("media_attachment.id = ?", id)
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return nil, m.conn.ProcessError(err)
}
return attachment, nil
diff --git a/internal/db/bundb/mention.go b/internal/db/bundb/mention.go
index 3c2c64cfd..81ad216cc 100644
--- a/internal/db/bundb/mention.go
+++ b/internal/db/bundb/mention.go
@@ -61,8 +61,7 @@ func (m *mentionDB) getMentionDB(ctx context.Context, id string) (*gtsmodel.Ment
q := m.newMentionQ(mention).
Where("mention.id = ?", id)
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return nil, m.conn.ProcessError(err)
}
diff --git a/internal/db/bundb/notification.go b/internal/db/bundb/notification.go
index d3be16168..212c97467 100644
--- a/internal/db/bundb/notification.go
+++ b/internal/db/bundb/notification.go
@@ -125,8 +125,7 @@ func (n *notificationDB) getNotificationDB(ctx context.Context, id string, dst *
q := n.newNotificationQ(dst).
Where("notification.id = ?", id)
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return n.conn.ProcessError(err)
}
diff --git a/internal/db/bundb/relationship.go b/internal/db/bundb/relationship.go
index 4f15c7772..a98a9f426 100644
--- a/internal/db/bundb/relationship.go
+++ b/internal/db/bundb/relationship.go
@@ -74,8 +74,7 @@ func (r *relationshipDB) GetBlock(ctx context.Context, account1 string, account2
Where("block.account_id = ?", account1).
Where("block.target_account_id = ?", account2)
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return nil, r.conn.ProcessError(err)
}
return block, nil
@@ -286,8 +285,7 @@ func (r *relationshipDB) GetAccountFollowRequests(ctx context.Context, accountID
q := r.newFollowQ(&followRequests).
Where("target_account_id = ?", accountID)
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return nil, r.conn.ProcessError(err)
}
return followRequests, nil
@@ -299,8 +297,7 @@ func (r *relationshipDB) GetAccountFollows(ctx context.Context, accountID string
q := r.newFollowQ(&follows).
Where("account_id = ?", accountID)
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return nil, r.conn.ProcessError(err)
}
return follows, nil
diff --git a/internal/db/bundb/session.go b/internal/db/bundb/session.go
index c8b09ec86..acc70a868 100644
--- a/internal/db/bundb/session.go
+++ b/internal/db/bundb/session.go
@@ -47,7 +47,7 @@ func (s *sessionDB) GetSession(ctx context.Context) (*gtsmodel.RouterSession, db
return nil, s.conn.ProcessError(err)
}
- if len(rss) <= 0 {
+ if len(rss) == 0 {
// no session created yet, so make one
return s.createSession(ctx)
}
diff --git a/internal/db/bundb/status.go b/internal/db/bundb/status.go
index 2c26a7df9..73e2cb4c0 100644
--- a/internal/db/bundb/status.go
+++ b/internal/db/bundb/status.go
@@ -23,6 +23,7 @@ import (
"context"
"time"
+ "github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/cache"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@@ -206,7 +207,11 @@ func (s *statusDB) GetStatusChildren(ctx context.Context, status *gtsmodel.Statu
children := []*gtsmodel.Status{}
for e := foundStatuses.Front(); e != nil; e = e.Next() {
// only append children, not the overall parent status
- entry := e.Value.(*gtsmodel.Status)
+ entry, ok := e.Value.(*gtsmodel.Status)
+ if !ok {
+ logrus.Panic("GetStatusChildren: found status could not be asserted to *gtsmodel.Status")
+ }
+
if entry.ID != status.ID {
children = append(children, entry)
}
@@ -233,7 +238,11 @@ func (s *statusDB) statusChildren(ctx context.Context, status *gtsmodel.Status,
for _, child := range immediateChildren {
insertLoop:
for e := foundStatuses.Front(); e != nil; e = e.Next() {
- entry := e.Value.(*gtsmodel.Status)
+ entry, ok := e.Value.(*gtsmodel.Status)
+ if !ok {
+ logrus.Panic("statusChildren: found status could not be asserted to *gtsmodel.Status")
+ }
+
if child.InReplyToAccountID != "" && entry.ID == child.InReplyToID {
foundStatuses.InsertAfter(child, e)
break insertLoop
@@ -306,8 +315,7 @@ func (s *statusDB) GetStatusFaves(ctx context.Context, status *gtsmodel.Status)
q := s.newFaveQ(&faves).
Where("status_id = ?", status.ID)
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return nil, s.conn.ProcessError(err)
}
return faves, nil
@@ -319,8 +327,7 @@ func (s *statusDB) GetStatusReblogs(ctx context.Context, status *gtsmodel.Status
q := s.newStatusQ(&reblogs).
Where("boost_of_id = ?", status.ID)
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return nil, s.conn.ProcessError(err)
}
return reblogs, nil
diff --git a/internal/db/bundb/timeline.go b/internal/db/bundb/timeline.go
index 0c4619ae8..fb17fc53c 100644
--- a/internal/db/bundb/timeline.go
+++ b/internal/db/bundb/timeline.go
@@ -91,8 +91,7 @@ func (t *timelineDB) GetHomeTimeline(ctx context.Context, accountID string, maxI
q = q.WhereGroup(" AND ", whereGroup)
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return nil, t.conn.ProcessError(err)
}
return statuses, nil
@@ -136,8 +135,7 @@ func (t *timelineDB) GetPublicTimeline(ctx context.Context, accountID string, ma
q = q.Limit(limit)
}
- err := q.Scan(ctx)
- if err != nil {
+ if err := q.Scan(ctx); err != nil {
return nil, t.conn.ProcessError(err)
}
return statuses, nil