From f257f779a996f64abeb1c74591f6f30ce2dbf2c3 Mon Sep 17 00:00:00 2001 From: tobi Date: Mon, 17 Mar 2025 18:16:59 +0100 Subject: [PATCH] find a bug and squish it up and all day long you'll have good luck --- internal/db/bundb/account.go | 15 ++++--- internal/db/bundb/account_test.go | 6 +++ .../20250314120945_add_gallery_web_layout.go | 45 +++++++++++++++++-- internal/web/profile.go | 7 ++- web/source/css/profile-gallery.css | 1 + 5 files changed, 63 insertions(+), 11 deletions(-) diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go index 37e298f7d..cfacc1742 100644 --- a/internal/db/bundb/account.go +++ b/internal/db/bundb/account.go @@ -1054,10 +1054,7 @@ func (a *accountDB) GetAccountWebStatuses( TableExpr("? AS ?", bun.Ident("statuses"), bun.Ident("status")). // Select only IDs from table Column("status.id"). - Where("? = ?", bun.Ident("status.account_id"), account.ID). - // Don't show replies or boosts. - Where("? IS NULL", bun.Ident("status.in_reply_to_uri")). - Where("? IS NULL", bun.Ident("status.boost_of_id")) + Where("? = ?", bun.Ident("status.account_id"), account.ID) // Select statuses for this account according // to their web visibility preference. @@ -1082,15 +1079,19 @@ func (a *accountDB) GetAccountWebStatuses( ) } - // Don't show local-only statuses on the web view. - q = q.Where("? = ?", bun.Ident("status.federated"), true) + // Don't show replies, boosts, or + // local-only statuses on the web view. + q = q. + Where("? IS NULL", bun.Ident("status.in_reply_to_uri")). + Where("? IS NULL", bun.Ident("status.boost_of_id")). + Where("? = ?", bun.Ident("status.federated"), true) // Respect media-only preference. if mediaOnly { q = qMediaOnly(ctx, q) } - // return only statuses LOWER (ie., older) than maxID + // Return only statuses LOWER (ie., older) than maxID if maxID == "" { maxID = id.Highest } diff --git a/internal/db/bundb/account_test.go b/internal/db/bundb/account_test.go index 0cd9560cd..e3d36855e 100644 --- a/internal/db/bundb/account_test.go +++ b/internal/db/bundb/account_test.go @@ -49,6 +49,12 @@ func (suite *AccountTestSuite) TestGetAccountStatuses() { suite.Len(statuses, 9) } +func (suite *AccountTestSuite) TestGetAccountWebStatusesMediaOnly() { + statuses, err := suite.db.GetAccountWebStatuses(context.Background(), suite.testAccounts["local_account_3"], true, 20, "") + suite.NoError(err) + suite.Len(statuses, 2) +} + func (suite *AccountTestSuite) TestGetAccountStatusesPageDown() { // get the first page statuses, err := suite.db.GetAccountStatuses(context.Background(), suite.testAccounts["local_account_1"].ID, 3, false, false, "", "", false, false) diff --git a/internal/db/bundb/migrations/20250314120945_add_gallery_web_layout.go b/internal/db/bundb/migrations/20250314120945_add_gallery_web_layout.go index 24dbb795f..b5aeeca3f 100644 --- a/internal/db/bundb/migrations/20250314120945_add_gallery_web_layout.go +++ b/internal/db/bundb/migrations/20250314120945_add_gallery_web_layout.go @@ -20,7 +20,7 @@ package migrations import ( "context" - "github.com/superseriousbusiness/gotosocial/internal/gtserror" + "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/uptrace/bun" ) @@ -29,14 +29,53 @@ func init() { return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error { // Add new column to settings. - if _, err := tx.NewAddColumn(). + if _, err := tx. + NewAddColumn(). Table("account_settings"). ColumnExpr( "? SMALLINT NOT NULL DEFAULT ?", bun.Ident("web_layout"), 1, ). Exec(ctx); err != nil { - return gtserror.Newf("error adding account_settings.web_layout: %w", err) + return err + } + + // Drop existing statuses web index as it's out of date. + log.Info(ctx, "updating statuses_profile_web_view_idx, this may take a while, please wait!") + if _, err := tx. + NewDropIndex(). + Index("statuses_profile_web_view_idx"). + IfExists(). + Exec(ctx); err != nil { + return err + } + + if _, err := tx. + NewCreateIndex(). + Table("statuses"). + Index("statuses_profile_web_view_idx"). + Column( + "account_id", + "visibility", + "in_reply_to_uri", + "boost_of_id", + "federated", + "attachments", + ). + IfNotExists(). + Exec(ctx); err != nil { + return err + } + + if _, err := tx. + NewCreateIndex(). + Table("statuses"). + Index("statuses_profile_web_view_sorting_idx"). + Column("account_id", "federated"). + ColumnExpr("? DESC", bun.Ident("id")). + IfNotExists(). + Exec(ctx); err != nil { + return err } return nil diff --git a/internal/web/profile.go b/internal/web/profile.go index fa59c2f62..52d918b48 100644 --- a/internal/web/profile.go +++ b/internal/web/profile.go @@ -146,7 +146,7 @@ func (m *Module) prepareProfile(c *gin.Context) *profile { statusResp, errWithCode := m.processor.Account().WebStatusesGet( ctx, account.ID, - false, // mediaOnly = false + mediaOnly, maxStatusID, ) if errWithCode != nil { @@ -169,6 +169,11 @@ func (m *Module) prepareProfile(c *gin.Context) *profile { // mode for the target account profile, and serves that. func (m *Module) profileGETHandler(c *gin.Context) { p := m.prepareProfile(c) + if p == nil { + // Something went wrong, + // error already written. + return + } // Choose desired web renderer for this acct. switch wrm := p.account.WebLayout; wrm { diff --git a/web/source/css/profile-gallery.css b/web/source/css/profile-gallery.css index 75d587e13..86186d413 100644 --- a/web/source/css/profile-gallery.css +++ b/web/source/css/profile-gallery.css @@ -92,6 +92,7 @@ aspect-ratio: 4/3; border: 0; border-radius: 0; + background: $bg; } }