summaryrefslogtreecommitdiff
path: root/internal/db
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db')
-rw-r--r--internal/db/bundb/account.go19
-rw-r--r--internal/db/bundb/basic_test.go2
-rw-r--r--internal/db/bundb/migrations/20230202212700_rename_account_webfingered_to_fetched.go44
-rw-r--r--internal/db/bundb/notification_test.go5
-rw-r--r--internal/db/bundb/session.go7
5 files changed, 64 insertions, 13 deletions
diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go
index 673d915ba..dccfee45b 100644
--- a/internal/db/bundb/account.go
+++ b/internal/db/bundb/account.go
@@ -21,7 +21,6 @@ package bundb
import (
"context"
"errors"
- "fmt"
"strings"
"time"
@@ -145,11 +144,27 @@ func (a *accountDB) getAccount(ctx context.Context, lookup string, dbQuery func(
return nil, err
}
+ if account.AvatarMediaAttachmentID != "" {
+ // Set the account's related avatar
+ account.AvatarMediaAttachment, err = a.state.DB.GetAttachmentByID(ctx, account.AvatarMediaAttachmentID)
+ if err != nil {
+ log.Errorf("error getting account %s avatar: %v", account.ID, err)
+ }
+ }
+
+ if account.HeaderMediaAttachmentID != "" {
+ // Set the account's related header
+ account.HeaderMediaAttachment, err = a.state.DB.GetAttachmentByID(ctx, account.HeaderMediaAttachmentID)
+ if err != nil {
+ log.Errorf("error getting account %s header: %v", account.ID, err)
+ }
+ }
+
if len(account.EmojiIDs) > 0 {
// Set the account's related emojis
account.Emojis, err = a.state.DB.GetEmojisByIDs(ctx, account.EmojiIDs)
if err != nil {
- return nil, fmt.Errorf("error getting account emojis: %w", err)
+ log.Errorf("error getting account %s emojis: %v", account.ID, err)
}
}
diff --git a/internal/db/bundb/basic_test.go b/internal/db/bundb/basic_test.go
index 6a03d04d1..86a9995fc 100644
--- a/internal/db/bundb/basic_test.go
+++ b/internal/db/bundb/basic_test.go
@@ -92,7 +92,7 @@ func (suite *BasicTestSuite) TestPutAccountWithBunDefaultFields() {
suite.Empty(a.StatusFormat)
suite.Equal(testAccount.URI, a.URI)
suite.Equal(testAccount.URL, a.URL)
- suite.Zero(testAccount.LastWebfingeredAt)
+ suite.Zero(testAccount.FetchedAt)
suite.Equal(testAccount.InboxURI, a.InboxURI)
suite.Equal(testAccount.OutboxURI, a.OutboxURI)
suite.Empty(a.FollowingURI)
diff --git a/internal/db/bundb/migrations/20230202212700_rename_account_webfingered_to_fetched.go b/internal/db/bundb/migrations/20230202212700_rename_account_webfingered_to_fetched.go
new file mode 100644
index 000000000..117347965
--- /dev/null
+++ b/internal/db/bundb/migrations/20230202212700_rename_account_webfingered_to_fetched.go
@@ -0,0 +1,44 @@
+/*
+ GoToSocial
+ Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package migrations
+
+import (
+ "context"
+
+ "github.com/uptrace/bun"
+)
+
+func init() {
+ up := func(ctx context.Context, db *bun.DB) error {
+ return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
+ _, err := tx.ExecContext(ctx, "ALTER TABLE ? RENAME COLUMN ? TO ?", bun.Ident("accounts"), bun.Ident("last_webfingered_at"), bun.Ident("fetched_at"))
+ return err
+ })
+ }
+
+ down := func(ctx context.Context, db *bun.DB) error {
+ return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
+ return nil
+ })
+ }
+
+ if err := Migrations.Register(up, down); err != nil {
+ panic(err)
+ }
+}
diff --git a/internal/db/bundb/notification_test.go b/internal/db/bundb/notification_test.go
index 0f5cef6fc..5bb1c7d49 100644
--- a/internal/db/bundb/notification_test.go
+++ b/internal/db/bundb/notification_test.go
@@ -39,10 +39,7 @@ func (suite *NotificationTestSuite) spamNotifs() {
zork := suite.testAccounts["local_account_1"]
for i := 0; i < notifCount; i++ {
- notifID, err := id.NewULID()
- if err != nil {
- panic(err)
- }
+ notifID := id.NewULID()
var targetAccountID string
if i%2 == 0 {
diff --git a/internal/db/bundb/session.go b/internal/db/bundb/session.go
index 846b5fe76..fbc739ce6 100644
--- a/internal/db/bundb/session.go
+++ b/internal/db/bundb/session.go
@@ -63,13 +63,8 @@ func (s *sessionDB) createSession(ctx context.Context) (*gtsmodel.RouterSession,
return nil, err
}
- id, err := id.NewULID()
- if err != nil {
- return nil, err
- }
-
rs := &gtsmodel.RouterSession{
- ID: id,
+ ID: id.NewULID(),
Auth: auth,
Crypt: crypt,
}