mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-07 11:58:08 -06:00
[performance] filter model and database table improvements (#4277)
- removes unnecessary fields / columns (created_at, updated_at)
- replaces filter.context_* columns with singular filter.contexts bit field which should save both struct memory and database space
- replaces filter.action string with integer enum type which should save both struct memory and database space
- adds links from filter to filter_* tables with Filter{}.KeywordIDs and Filter{}.StatusIDs fields (this also means we now have those ID slices cached, which reduces some lookups)
- removes account_id fields from filter_* tables, since there's a more direct connection between filter and filter_* tables, and filter.account_id already exists
- refactors a bunch of the filter processor logic to save on code repetition, factor in the above changes, fix a few bugs with missed error returns and bring it more in-line with some of our newer code
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4277
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
9d5af6c3dc
commit
996da6e029
82 changed files with 2440 additions and 1722 deletions
|
|
@ -25,8 +25,8 @@ import (
|
|||
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
|
||||
apiutil "code.superseriousbusiness.org/gotosocial/internal/api/util"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/db"
|
||||
statusfilter "code.superseriousbusiness.org/gotosocial/internal/filter/status"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/log"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/util"
|
||||
)
|
||||
|
|
@ -56,7 +56,7 @@ func (p *Processor) FavedTimelineGet(ctx context.Context, authed *apiutil.Auth,
|
|||
continue
|
||||
}
|
||||
|
||||
apiStatus, err := p.converter.StatusToAPIStatus(ctx, s, authed.Account, statusfilter.FilterContextNone, nil)
|
||||
apiStatus, err := p.converter.StatusToAPIStatus(ctx, s, authed.Account, gtsmodel.FilterContextNone, nil)
|
||||
if err != nil {
|
||||
log.Errorf(ctx, "error convering to api status: %v", err)
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import (
|
|||
"net/url"
|
||||
|
||||
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
|
||||
statusfilter "code.superseriousbusiness.org/gotosocial/internal/filter/status"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/log"
|
||||
|
|
@ -77,7 +76,7 @@ func (p *Processor) HomeTimelineGet(
|
|||
pageQuery,
|
||||
|
||||
// Status filter context.
|
||||
statusfilter.FilterContextHome,
|
||||
gtsmodel.FilterContextHome,
|
||||
|
||||
// Database load function.
|
||||
func(pg *paging.Page) (statuses []*gtsmodel.Status, err error) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import (
|
|||
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/id"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/paging"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/util"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
|
|
@ -49,24 +48,20 @@ func (suite *HomeTestSuite) TestHomeTimelineGetHideFiltered() {
|
|||
filteredStatus = suite.testStatuses["admin_account_status_2"]
|
||||
filteredStatusFound = false
|
||||
filterID = id.NewULID()
|
||||
filter = >smodel.Filter{
|
||||
filterStatusID = id.NewULID()
|
||||
filterStatus = >smodel.FilterStatus{
|
||||
ID: filterStatusID,
|
||||
FilterID: filterID,
|
||||
StatusID: filteredStatus.ID,
|
||||
}
|
||||
filter = >smodel.Filter{
|
||||
ID: filterID,
|
||||
AccountID: requester.ID,
|
||||
Title: "timeline filtering test",
|
||||
Action: gtsmodel.FilterActionHide,
|
||||
Statuses: []*gtsmodel.FilterStatus{
|
||||
{
|
||||
ID: id.NewULID(),
|
||||
AccountID: requester.ID,
|
||||
FilterID: filterID,
|
||||
StatusID: filteredStatus.ID,
|
||||
},
|
||||
},
|
||||
ContextHome: util.Ptr(true),
|
||||
ContextNotifications: util.Ptr(false),
|
||||
ContextPublic: util.Ptr(false),
|
||||
ContextThread: util.Ptr(false),
|
||||
ContextAccount: util.Ptr(false),
|
||||
Statuses: []*gtsmodel.FilterStatus{filterStatus},
|
||||
StatusIDs: []string{filterStatusID},
|
||||
Contexts: gtsmodel.FilterContexts(gtsmodel.FilterContextHome),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -95,6 +90,11 @@ func (suite *HomeTestSuite) TestHomeTimelineGetHideFiltered() {
|
|||
// Clear the timeline to drop all cached statuses.
|
||||
suite.state.Caches.Timelines.Home.Clear(requester.ID)
|
||||
|
||||
// Create the filter status associated with the main filter.
|
||||
if err := suite.db.PutFilterStatus(ctx, filterStatus); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
// Create a filter to hide one status on the timeline.
|
||||
if err := suite.db.PutFilter(ctx, filter); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import (
|
|||
|
||||
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/db"
|
||||
statusfilter "code.superseriousbusiness.org/gotosocial/internal/filter/status"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/gtscontext"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
|
||||
|
|
@ -88,7 +87,7 @@ func (p *Processor) ListTimelineGet(
|
|||
nil,
|
||||
|
||||
// Status filter context.
|
||||
statusfilter.FilterContextHome,
|
||||
gtsmodel.FilterContextHome,
|
||||
|
||||
// Database load function.
|
||||
func(pg *paging.Page) (statuses []*gtsmodel.Status, err error) {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func (p *Processor) NotificationsGet(
|
|||
return util.EmptyPageableResponse(), nil
|
||||
}
|
||||
|
||||
filters, err := p.state.DB.GetFiltersForAccountID(ctx, requester.ID)
|
||||
filters, err := p.state.DB.GetFiltersByAccountID(ctx, requester.ID)
|
||||
if err != nil {
|
||||
err = gtserror.Newf("error getting account %s filters: %w", requester.ID, err)
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import (
|
|||
"context"
|
||||
|
||||
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
|
||||
statusfilter "code.superseriousbusiness.org/gotosocial/internal/filter/status"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/log"
|
||||
|
|
@ -79,7 +78,7 @@ func (p *Processor) publicTimelineGet(
|
|||
localOnlyFalse,
|
||||
|
||||
// Status filter context.
|
||||
statusfilter.FilterContextPublic,
|
||||
gtsmodel.FilterContextPublic,
|
||||
|
||||
// Database load function.
|
||||
func(pg *paging.Page) (statuses []*gtsmodel.Status, err error) {
|
||||
|
|
@ -148,7 +147,7 @@ func (p *Processor) localTimelineGet(
|
|||
localOnlyTrue,
|
||||
|
||||
// Status filter context.
|
||||
statusfilter.FilterContextPublic,
|
||||
gtsmodel.FilterContextPublic,
|
||||
|
||||
// Database load function.
|
||||
func(pg *paging.Page) (statuses []*gtsmodel.Status, err error) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import (
|
|||
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/id"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/paging"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/util"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
|
|
@ -110,24 +109,20 @@ func (suite *PublicTestSuite) TestPublicTimelineGetHideFiltered() {
|
|||
filteredStatus = suite.testStatuses["admin_account_status_2"]
|
||||
filteredStatusFound = false
|
||||
filterID = id.NewULID()
|
||||
filter = >smodel.Filter{
|
||||
filterStatusID = id.NewULID()
|
||||
filterStatus = >smodel.FilterStatus{
|
||||
ID: filterStatusID,
|
||||
FilterID: filterID,
|
||||
StatusID: filteredStatus.ID,
|
||||
}
|
||||
filter = >smodel.Filter{
|
||||
ID: filterID,
|
||||
AccountID: requester.ID,
|
||||
Title: "timeline filtering test",
|
||||
Action: gtsmodel.FilterActionHide,
|
||||
Statuses: []*gtsmodel.FilterStatus{
|
||||
{
|
||||
ID: id.NewULID(),
|
||||
AccountID: requester.ID,
|
||||
FilterID: filterID,
|
||||
StatusID: filteredStatus.ID,
|
||||
},
|
||||
},
|
||||
ContextHome: util.Ptr(false),
|
||||
ContextNotifications: util.Ptr(false),
|
||||
ContextPublic: util.Ptr(true),
|
||||
ContextThread: util.Ptr(false),
|
||||
ContextAccount: util.Ptr(false),
|
||||
Statuses: []*gtsmodel.FilterStatus{filterStatus},
|
||||
StatusIDs: []string{filterStatusID},
|
||||
Contexts: gtsmodel.FilterContexts(gtsmodel.FilterContextPublic),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -153,6 +148,11 @@ func (suite *PublicTestSuite) TestPublicTimelineGetHideFiltered() {
|
|||
suite.FailNow("precondition failed: status we would filter isn't present in unfiltered timeline")
|
||||
}
|
||||
|
||||
// Create the filter status associated with the main filter.
|
||||
if err := suite.db.PutFilterStatus(ctx, filterStatus); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
// Create a filter to hide one status on the timeline.
|
||||
if err := suite.db.PutFilter(ctx, filter); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import (
|
|||
|
||||
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/db"
|
||||
statusfilter "code.superseriousbusiness.org/gotosocial/internal/filter/status"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/log"
|
||||
|
|
@ -87,7 +86,7 @@ func (p *Processor) TagTimelineGet(
|
|||
nil,
|
||||
|
||||
// Status filter context.
|
||||
statusfilter.FilterContextPublic,
|
||||
gtsmodel.FilterContextPublic,
|
||||
|
||||
// Database load function.
|
||||
func(pg *paging.Page) (statuses []*gtsmodel.Status, err error) {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func (p *Processor) getStatusTimeline(
|
|||
page *paging.Page,
|
||||
pagePath string,
|
||||
pageQuery url.Values,
|
||||
filterCtx statusfilter.FilterContext,
|
||||
filterCtx gtsmodel.FilterContext,
|
||||
loadPage func(*paging.Page) (statuses []*gtsmodel.Status, err error),
|
||||
filter func(*gtsmodel.Status) (delete bool),
|
||||
postFilter func(*gtsmodel.Status) (remove bool),
|
||||
|
|
@ -83,7 +83,7 @@ func (p *Processor) getStatusTimeline(
|
|||
|
||||
if requester != nil {
|
||||
// Fetch all filters relevant for requesting account.
|
||||
filters, err = p.state.DB.GetFiltersForAccountID(ctx,
|
||||
filters, err = p.state.DB.GetFiltersByAccountID(ctx,
|
||||
requester.ID,
|
||||
)
|
||||
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue