mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-30 23:12:25 -05:00 
			
		
		
		
	Remove content and related fields from boosts (#3131)
These duplicate the content of the target and aren't necessary for anything. - Stops copying some fields from target when boosting or processing a remote boost - Adds a migration to null out existing duplicate data - Updates tests
This commit is contained in:
		
					parent
					
						
							
								2d921d9d7c
							
						
					
				
			
			
				commit
				
					
						86a59db711
					
				
			
		
					 5 changed files with 68 additions and 19 deletions
				
			
		|  | @ -80,8 +80,8 @@ func (suite *StatusBoostTestSuite) TestPostBoost() { | ||||||
| 	suite.False(statusReply.Sensitive) | 	suite.False(statusReply.Sensitive) | ||||||
| 	suite.Equal(apimodel.VisibilityPublic, statusReply.Visibility) | 	suite.Equal(apimodel.VisibilityPublic, statusReply.Visibility) | ||||||
| 
 | 
 | ||||||
| 	suite.Equal(targetStatus.ContentWarning, statusReply.SpoilerText) | 	suite.Empty(statusReply.SpoilerText) | ||||||
| 	suite.Equal(targetStatus.Content, statusReply.Content) | 	suite.Empty(statusReply.Content) | ||||||
| 	suite.Equal("the_mighty_zork", statusReply.Account.Username) | 	suite.Equal("the_mighty_zork", statusReply.Account.Username) | ||||||
| 	suite.Len(statusReply.MediaAttachments, 0) | 	suite.Len(statusReply.MediaAttachments, 0) | ||||||
| 	suite.Len(statusReply.Mentions, 0) | 	suite.Len(statusReply.Mentions, 0) | ||||||
|  | @ -146,8 +146,8 @@ func (suite *StatusBoostTestSuite) TestPostBoostOwnFollowersOnly() { | ||||||
| 	suite.False(responseStatus.Sensitive) | 	suite.False(responseStatus.Sensitive) | ||||||
| 	suite.Equal(suite.tc.VisToAPIVis(context.Background(), testStatus.Visibility), responseStatus.Visibility) | 	suite.Equal(suite.tc.VisToAPIVis(context.Background(), testStatus.Visibility), responseStatus.Visibility) | ||||||
| 
 | 
 | ||||||
| 	suite.Equal(testStatus.ContentWarning, responseStatus.SpoilerText) | 	suite.Empty(responseStatus.SpoilerText) | ||||||
| 	suite.Equal(testStatus.Content, responseStatus.Content) | 	suite.Empty(responseStatus.Content) | ||||||
| 	suite.Equal("the_mighty_zork", responseStatus.Account.Username) | 	suite.Equal("the_mighty_zork", responseStatus.Account.Username) | ||||||
| 	suite.Len(responseStatus.MediaAttachments, 0) | 	suite.Len(responseStatus.MediaAttachments, 0) | ||||||
| 	suite.Len(responseStatus.Mentions, 0) | 	suite.Len(responseStatus.Mentions, 0) | ||||||
|  |  | ||||||
|  | @ -0,0 +1,56 @@ | ||||||
|  | // GoToSocial | ||||||
|  | // Copyright (C) GoToSocial Authors admin@gotosocial.org | ||||||
|  | // SPDX-License-Identifier: AGPL-3.0-or-later | ||||||
|  | // | ||||||
|  | // 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/superseriousbusiness/gotosocial/internal/gtsmodel" | ||||||
|  | 	"github.com/uptrace/bun" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | // Boosts previously duplicated some columns from their targets. | ||||||
|  | // This isn't necessary, so we remove them here. | ||||||
|  | // Admins may want to vacuum after running this migration. | ||||||
|  | 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.NewUpdate(). | ||||||
|  | 				Model((*gtsmodel.Status)(nil)). | ||||||
|  | 				Where("boost_of_id IS NOT NULL"). | ||||||
|  | 				SetColumn("content", "NULL"). | ||||||
|  | 				SetColumn("content_warning", "NULL"). | ||||||
|  | 				SetColumn("text", "NULL"). | ||||||
|  | 				SetColumn("language", "NULL"). | ||||||
|  | 				SetColumn("sensitive", "FALSE"). | ||||||
|  | 				Exec(ctx) | ||||||
|  | 
 | ||||||
|  | 			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) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | @ -26,6 +26,7 @@ import ( | ||||||
| 	"github.com/superseriousbusiness/gotosocial/internal/gtserror" | 	"github.com/superseriousbusiness/gotosocial/internal/gtserror" | ||||||
| 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" | 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" | ||||||
| 	"github.com/superseriousbusiness/gotosocial/internal/id" | 	"github.com/superseriousbusiness/gotosocial/internal/id" | ||||||
|  | 	"github.com/superseriousbusiness/gotosocial/internal/util" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // EnrichAnnounce enriches the given boost wrapper status | // EnrichAnnounce enriches the given boost wrapper status | ||||||
|  | @ -78,14 +79,12 @@ func (d *Dereferencer) EnrichAnnounce( | ||||||
| 	// original URI was an indirect link. | 	// original URI was an indirect link. | ||||||
| 	boost.BoostOfURI = target.URI | 	boost.BoostOfURI = target.URI | ||||||
| 
 | 
 | ||||||
|  | 	// Boosts are not considered sensitive even if their target is. | ||||||
|  | 	boost.Sensitive = util.Ptr(false) | ||||||
|  | 
 | ||||||
| 	// Populate remaining fields on | 	// Populate remaining fields on | ||||||
| 	// the boost wrapper using target. | 	// the boost wrapper using target. | ||||||
| 	boost.Content = target.Content |  | ||||||
| 	boost.ContentWarning = target.ContentWarning |  | ||||||
| 	boost.ActivityStreamsType = target.ActivityStreamsType | 	boost.ActivityStreamsType = target.ActivityStreamsType | ||||||
| 	boost.Sensitive = target.Sensitive |  | ||||||
| 	boost.Language = target.Language |  | ||||||
| 	boost.Text = target.Text |  | ||||||
| 	boost.BoostOfID = target.ID | 	boost.BoostOfID = target.ID | ||||||
| 	boost.BoostOf = target | 	boost.BoostOf = target | ||||||
| 	boost.BoostOfAccountID = target.AccountID | 	boost.BoostOfAccountID = target.AccountID | ||||||
|  |  | ||||||
|  | @ -81,14 +81,12 @@ func (c *Converter) StatusToBoost( | ||||||
| 		MentionIDs:    []string{}, | 		MentionIDs:    []string{}, | ||||||
| 		EmojiIDs:      []string{}, | 		EmojiIDs:      []string{}, | ||||||
| 
 | 
 | ||||||
|  | 		// Boosts are not considered sensitive even if their target is. | ||||||
|  | 		Sensitive: util.Ptr(false), | ||||||
|  | 
 | ||||||
| 		// Remaining fields all | 		// Remaining fields all | ||||||
| 		// taken from boosted status. | 		// taken from boosted status. | ||||||
| 		Content:             target.Content, |  | ||||||
| 		ContentWarning:      target.ContentWarning, |  | ||||||
| 		ActivityStreamsType: target.ActivityStreamsType, | 		ActivityStreamsType: target.ActivityStreamsType, | ||||||
| 		Sensitive:           util.Ptr(*target.Sensitive), |  | ||||||
| 		Language:            target.Language, |  | ||||||
| 		Text:                target.Text, |  | ||||||
| 		BoostOfID:           target.ID, | 		BoostOfID:           target.ID, | ||||||
| 		BoostOf:             target, | 		BoostOf:             target, | ||||||
| 		BoostOfAccountID:    target.AccountID, | 		BoostOfAccountID:    target.AccountID, | ||||||
|  |  | ||||||
|  | @ -1488,8 +1488,6 @@ func NewTestStatuses() map[string]*gtsmodel.Status { | ||||||
| 			ID:                       "01G36SF3V6Y6V5BF9P4R7PQG7G", | 			ID:                       "01G36SF3V6Y6V5BF9P4R7PQG7G", | ||||||
| 			URI:                      "http://localhost:8080/users/admin/statuses/01G36SF3V6Y6V5BF9P4R7PQG7G", | 			URI:                      "http://localhost:8080/users/admin/statuses/01G36SF3V6Y6V5BF9P4R7PQG7G", | ||||||
| 			URL:                      "http://localhost:8080/@admin/statuses/01G36SF3V6Y6V5BF9P4R7PQG7G", | 			URL:                      "http://localhost:8080/@admin/statuses/01G36SF3V6Y6V5BF9P4R7PQG7G", | ||||||
| 			Content:                  "hello everyone!", |  | ||||||
| 			Text:                     "hello everyone!", |  | ||||||
| 			CreatedAt:                TimeMustParse("2021-10-20T12:41:37+02:00"), | 			CreatedAt:                TimeMustParse("2021-10-20T12:41:37+02:00"), | ||||||
| 			UpdatedAt:                TimeMustParse("2021-10-20T12:41:37+02:00"), | 			UpdatedAt:                TimeMustParse("2021-10-20T12:41:37+02:00"), | ||||||
| 			Local:                    util.Ptr(true), | 			Local:                    util.Ptr(true), | ||||||
|  | @ -1501,10 +1499,8 @@ func NewTestStatuses() map[string]*gtsmodel.Status { | ||||||
| 			BoostOfID:                "01F8MHAMCHF6Y650WCRSCP4WMY", | 			BoostOfID:                "01F8MHAMCHF6Y650WCRSCP4WMY", | ||||||
| 			BoostOfAccountID:         "01F8MH1H7YV1Z7D2C8K2730QBF", | 			BoostOfAccountID:         "01F8MH1H7YV1Z7D2C8K2730QBF", | ||||||
| 			ThreadID:                 "", | 			ThreadID:                 "", | ||||||
| 			ContentWarning:           "introduction post", |  | ||||||
| 			Visibility:               gtsmodel.VisibilityPublic, | 			Visibility:               gtsmodel.VisibilityPublic, | ||||||
| 			Sensitive:                util.Ptr(true), | 			Sensitive:                util.Ptr(false), | ||||||
| 			Language:                 "en", |  | ||||||
| 			CreatedWithApplicationID: "01F8MGXQRHYF5QPMTMXP78QC2F", | 			CreatedWithApplicationID: "01F8MGXQRHYF5QPMTMXP78QC2F", | ||||||
| 			Federated:                util.Ptr(true), | 			Federated:                util.Ptr(true), | ||||||
| 			ActivityStreamsType:      ap.ObjectNote, | 			ActivityStreamsType:      ap.ObjectNote, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue