| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | // 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 common | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							|  |  |  | 	"errors" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-26 15:34:10 +02:00
										 |  |  | 	apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/db" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/federation/dereferencing" | 
					
						
							|  |  |  | 	statusfilter "code.superseriousbusiness.org/gotosocial/internal/filter/status" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/filter/usermute" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/gtserror" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/gtsmodel" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/log" | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-23 17:54:44 +00:00
										 |  |  | // GetOwnStatus fetches the given status with ID, | 
					
						
							|  |  |  | // and ensures that it belongs to given requester. | 
					
						
							|  |  |  | func (p *Processor) GetOwnStatus( | 
					
						
							|  |  |  | 	ctx context.Context, | 
					
						
							|  |  |  | 	requester *gtsmodel.Account, | 
					
						
							|  |  |  | 	targetID string, | 
					
						
							|  |  |  | ) ( | 
					
						
							|  |  |  | 	*gtsmodel.Status, | 
					
						
							|  |  |  | 	gtserror.WithCode, | 
					
						
							|  |  |  | ) { | 
					
						
							|  |  |  | 	target, err := p.state.DB.GetStatusByID(ctx, targetID) | 
					
						
							|  |  |  | 	if err != nil && !errors.Is(err, db.ErrNoEntries) { | 
					
						
							|  |  |  | 		err := gtserror.Newf("error getting from db: %w", err) | 
					
						
							|  |  |  | 		return nil, gtserror.NewErrorInternalError(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case target == nil: | 
					
						
							|  |  |  | 		const text = "target status not found" | 
					
						
							|  |  |  | 		return nil, gtserror.NewErrorNotFound( | 
					
						
							|  |  |  | 			errors.New(text), | 
					
						
							|  |  |  | 			text, | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case target.AccountID != requester.ID: | 
					
						
							|  |  |  | 		return nil, gtserror.NewErrorNotFound( | 
					
						
							|  |  |  | 			errors.New("status does not belong to requester"), | 
					
						
							|  |  |  | 			"target status not found", | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return target, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-09 15:24:49 +01:00
										 |  |  | // GetTargetStatusBy fetches the target status with db load | 
					
						
							|  |  |  | // function, given the authorized (or, nil) requester's | 
					
						
							|  |  |  | // account. This returns an approprate gtserror.WithCode | 
					
						
							|  |  |  | // accounting for not found and visibility to requester. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // window can be used to force refresh of the target if it's | 
					
						
							|  |  |  | // deemed to be stale. Falls back to default window if nil. | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | func (p *Processor) GetTargetStatusBy( | 
					
						
							|  |  |  | 	ctx context.Context, | 
					
						
							|  |  |  | 	requester *gtsmodel.Account, | 
					
						
							|  |  |  | 	getTargetFromDB func() (*gtsmodel.Status, error), | 
					
						
							| 
									
										
										
										
											2024-02-09 15:24:49 +01:00
										 |  |  | 	window *dereferencing.FreshnessWindow, | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | ) ( | 
					
						
							|  |  |  | 	status *gtsmodel.Status, | 
					
						
							|  |  |  | 	visible bool, | 
					
						
							|  |  |  | 	errWithCode gtserror.WithCode, | 
					
						
							|  |  |  | ) { | 
					
						
							|  |  |  | 	// Fetch the target status from db. | 
					
						
							|  |  |  | 	target, err := getTargetFromDB() | 
					
						
							|  |  |  | 	if err != nil && !errors.Is(err, db.ErrNoEntries) { | 
					
						
							| 
									
										
										
										
											2024-09-23 11:53:42 +00:00
										 |  |  | 		err := gtserror.Newf("error getting from db: %w", err) | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 		return nil, false, gtserror.NewErrorInternalError(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if target == nil { | 
					
						
							|  |  |  | 		// DB loader could not find status in database. | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		const text = "target status not found" | 
					
						
							|  |  |  | 		return nil, false, gtserror.NewErrorNotFound( | 
					
						
							|  |  |  | 			errors.New(text), | 
					
						
							|  |  |  | 			text, | 
					
						
							|  |  |  | 		) | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Check whether target status is visible to requesting account. | 
					
						
							| 
									
										
										
										
											2024-07-24 13:27:42 +02:00
										 |  |  | 	visible, err = p.visFilter.StatusVisible(ctx, requester, target) | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2024-09-23 11:53:42 +00:00
										 |  |  | 		err := gtserror.Newf("error checking visibility: %w", err) | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 		return nil, false, gtserror.NewErrorInternalError(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if requester != nil && visible { | 
					
						
							| 
									
										
										
										
											2024-07-21 13:04:19 +01:00
										 |  |  | 		// Only refresh status if visible to requester, | 
					
						
							|  |  |  | 		// and there is *authorized* requester to prevent | 
					
						
							|  |  |  | 		// a possible DOS vector for unauthorized clients. | 
					
						
							|  |  |  | 		latest, _, err := p.federator.RefreshStatus(ctx, | 
					
						
							|  |  |  | 			requester.Username, | 
					
						
							|  |  |  | 			target, | 
					
						
							|  |  |  | 			nil, | 
					
						
							|  |  |  | 			window, | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			log.Errorf(ctx, "error refreshing target %s: %v", target.URI, err) | 
					
						
							|  |  |  | 			return target, visible, nil | 
					
						
							| 
									
										
										
										
											2023-12-15 14:24:39 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-07-21 13:04:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Set latest. | 
					
						
							|  |  |  | 		target = latest | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return target, visible, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-15 14:24:39 +00:00
										 |  |  | // GetVisibleTargetStatus calls GetTargetStatusBy(), | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | // but converts a non-visible result to not-found error. | 
					
						
							| 
									
										
										
										
											2024-02-09 15:24:49 +01:00
										 |  |  | // | 
					
						
							|  |  |  | // window can be used to force refresh of the target if it's | 
					
						
							|  |  |  | // deemed to be stale. Falls back to default window if nil. | 
					
						
							| 
									
										
										
										
											2023-12-15 14:24:39 +00:00
										 |  |  | func (p *Processor) GetVisibleTargetStatusBy( | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 	ctx context.Context, | 
					
						
							|  |  |  | 	requester *gtsmodel.Account, | 
					
						
							| 
									
										
										
										
											2023-12-15 14:24:39 +00:00
										 |  |  | 	getTargetFromDB func() (*gtsmodel.Status, error), | 
					
						
							| 
									
										
										
										
											2024-02-09 15:24:49 +01:00
										 |  |  | 	window *dereferencing.FreshnessWindow, | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | ) ( | 
					
						
							|  |  |  | 	status *gtsmodel.Status, | 
					
						
							|  |  |  | 	errWithCode gtserror.WithCode, | 
					
						
							|  |  |  | ) { | 
					
						
							|  |  |  | 	// Fetch the target status by ID from the database. | 
					
						
							| 
									
										
										
										
											2023-12-15 14:24:39 +00:00
										 |  |  | 	target, visible, errWithCode := p.GetTargetStatusBy(ctx, | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 		requester, | 
					
						
							| 
									
										
										
										
											2023-12-15 14:24:39 +00:00
										 |  |  | 		getTargetFromDB, | 
					
						
							| 
									
										
										
										
											2024-02-09 15:24:49 +01:00
										 |  |  | 		window, | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 	) | 
					
						
							|  |  |  | 	if errWithCode != nil { | 
					
						
							|  |  |  | 		return nil, errWithCode | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !visible { | 
					
						
							|  |  |  | 		// Target should not be seen by requester. | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		const text = "target status not found" | 
					
						
							|  |  |  | 		return nil, gtserror.NewErrorNotFound( | 
					
						
							|  |  |  | 			errors.New(text), | 
					
						
							|  |  |  | 			text, | 
					
						
							|  |  |  | 		) | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return target, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-15 14:24:39 +00:00
										 |  |  | // GetVisibleTargetStatus calls GetVisibleTargetStatusBy(), | 
					
						
							|  |  |  | // passing in a database function that fetches by status ID. | 
					
						
							| 
									
										
										
										
											2024-02-09 15:24:49 +01:00
										 |  |  | // | 
					
						
							|  |  |  | // window can be used to force refresh of the target if it's | 
					
						
							|  |  |  | // deemed to be stale. Falls back to default window if nil. | 
					
						
							| 
									
										
										
										
											2023-12-15 14:24:39 +00:00
										 |  |  | func (p *Processor) GetVisibleTargetStatus( | 
					
						
							|  |  |  | 	ctx context.Context, | 
					
						
							|  |  |  | 	requester *gtsmodel.Account, | 
					
						
							|  |  |  | 	targetID string, | 
					
						
							| 
									
										
										
										
											2024-02-09 15:24:49 +01:00
										 |  |  | 	window *dereferencing.FreshnessWindow, | 
					
						
							| 
									
										
										
										
											2023-12-15 14:24:39 +00:00
										 |  |  | ) ( | 
					
						
							|  |  |  | 	status *gtsmodel.Status, | 
					
						
							|  |  |  | 	errWithCode gtserror.WithCode, | 
					
						
							|  |  |  | ) { | 
					
						
							|  |  |  | 	return p.GetVisibleTargetStatusBy(ctx, requester, func() (*gtsmodel.Status, error) { | 
					
						
							|  |  |  | 		return p.state.DB.GetStatusByID(ctx, targetID) | 
					
						
							| 
									
										
										
										
											2024-02-09 15:24:49 +01:00
										 |  |  | 	}, window) | 
					
						
							| 
									
										
										
										
											2023-12-15 14:24:39 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-01 15:27:15 +01:00
										 |  |  | // UnwrapIfBoost "unwraps" the given status if | 
					
						
							|  |  |  | // it's a boost wrapper, by returning the boosted | 
					
						
							|  |  |  | // status it targets (pending visibility checks). | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // Just returns the input status if it's not a boost. | 
					
						
							|  |  |  | func (p *Processor) UnwrapIfBoost( | 
					
						
							|  |  |  | 	ctx context.Context, | 
					
						
							|  |  |  | 	requester *gtsmodel.Account, | 
					
						
							|  |  |  | 	status *gtsmodel.Status, | 
					
						
							|  |  |  | ) (*gtsmodel.Status, gtserror.WithCode) { | 
					
						
							|  |  |  | 	if status.BoostOfID == "" { | 
					
						
							|  |  |  | 		return status, nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return p.GetVisibleTargetStatus(ctx, | 
					
						
							| 
									
										
										
										
											2023-12-15 14:24:39 +00:00
										 |  |  | 		requester, | 
					
						
							|  |  |  | 		status.BoostOfID, | 
					
						
							| 
									
										
										
										
											2024-02-09 15:24:49 +01:00
										 |  |  | 		nil, | 
					
						
							| 
									
										
										
										
											2023-12-01 15:27:15 +01:00
										 |  |  | 	) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | // GetAPIStatus fetches the appropriate API status model for target. | 
					
						
							|  |  |  | func (p *Processor) GetAPIStatus( | 
					
						
							|  |  |  | 	ctx context.Context, | 
					
						
							|  |  |  | 	requester *gtsmodel.Account, | 
					
						
							|  |  |  | 	target *gtsmodel.Status, | 
					
						
							|  |  |  | ) ( | 
					
						
							|  |  |  | 	apiStatus *apimodel.Status, | 
					
						
							|  |  |  | 	errWithCode gtserror.WithCode, | 
					
						
							|  |  |  | ) { | 
					
						
							| 
									
										
										
										
											2024-09-23 11:53:42 +00:00
										 |  |  | 	apiStatus, err := p.converter.StatusToAPIStatus(ctx, | 
					
						
							|  |  |  | 		target, | 
					
						
							|  |  |  | 		requester, | 
					
						
							|  |  |  | 		statusfilter.FilterContextNone, | 
					
						
							|  |  |  | 		nil, | 
					
						
							|  |  |  | 		nil, | 
					
						
							|  |  |  | 	) | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2024-09-23 11:53:42 +00:00
										 |  |  | 		err := gtserror.Newf("error converting: %w", err) | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 		return nil, gtserror.NewErrorInternalError(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return apiStatus, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-23 11:53:42 +00:00
										 |  |  | // GetVisibleAPIStatuses converts a slice of statuses to API | 
					
						
							|  |  |  | // model statuses, filtering according to visibility to requester | 
					
						
							|  |  |  | // along with given filter context, filters and user mutes. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // Please note that all errors will be logged at ERROR level, | 
					
						
							|  |  |  | // but will not be returned. Callers are likely to run into | 
					
						
							|  |  |  | // show-stopping errors in the lead-up to this function. | 
					
						
							|  |  |  | func (p *Processor) GetVisibleAPIStatuses( | 
					
						
							|  |  |  | 	ctx context.Context, | 
					
						
							|  |  |  | 	requester *gtsmodel.Account, | 
					
						
							|  |  |  | 	statuses []*gtsmodel.Status, | 
					
						
							|  |  |  | 	filterContext statusfilter.FilterContext, | 
					
						
							|  |  |  | 	filters []*gtsmodel.Filter, | 
					
						
							|  |  |  | 	userMutes []*gtsmodel.UserMute, | 
					
						
							|  |  |  | ) []apimodel.Status { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Start new log entry with | 
					
						
							|  |  |  | 	// the calling function name | 
					
						
							|  |  |  | 	// as a field in each entry. | 
					
						
							|  |  |  | 	l := log.WithContext(ctx). | 
					
						
							|  |  |  | 		WithField("caller", log.Caller(3)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Compile mutes to useable user mutes for type converter. | 
					
						
							|  |  |  | 	compUserMutes := usermute.NewCompiledUserMuteList(userMutes) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Iterate filtered statuses for conversion to API model. | 
					
						
							|  |  |  | 	apiStatuses := make([]apimodel.Status, 0, len(statuses)) | 
					
						
							|  |  |  | 	for _, status := range statuses { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Check whether status is visible to requester. | 
					
						
							|  |  |  | 		visible, err := p.visFilter.StatusVisible(ctx, | 
					
						
							|  |  |  | 			requester, | 
					
						
							|  |  |  | 			status, | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			l.Errorf("error checking visibility: %v", err) | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if !visible { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Convert to API status, taking mute / filter into account. | 
					
						
							|  |  |  | 		apiStatus, err := p.converter.StatusToAPIStatus(ctx, | 
					
						
							|  |  |  | 			status, | 
					
						
							|  |  |  | 			requester, | 
					
						
							|  |  |  | 			filterContext, | 
					
						
							|  |  |  | 			filters, | 
					
						
							|  |  |  | 			compUserMutes, | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 		if err != nil && !errors.Is(err, statusfilter.ErrHideStatus) { | 
					
						
							|  |  |  | 			l.Errorf("error converting: %v", err) | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-04 19:23:18 +02:00
										 |  |  | 		if apiStatus == nil { | 
					
						
							|  |  |  | 			// Status was | 
					
						
							|  |  |  | 			// filtered out. | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-23 11:53:42 +00:00
										 |  |  | 		// Append converted status to return slice. | 
					
						
							|  |  |  | 		apiStatuses = append(apiStatuses, *apiStatus) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return apiStatuses | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | // InvalidateTimelinedStatus is a shortcut function for invalidating the cached | 
					
						
							|  |  |  | // representation one status in the home timeline and all list timelines of the | 
					
						
							|  |  |  | // given accountID. It should only be called in cases where a status update | 
					
						
							|  |  |  | // does *not* need to be passed into the processor via the worker queue, since | 
					
						
							|  |  |  | // such invalidation will, in that case, be handled by the processor instead. | 
					
						
							|  |  |  | func (p *Processor) InvalidateTimelinedStatus(ctx context.Context, accountID string, statusID string) error { | 
					
						
							|  |  |  | 	// Get lists first + bail if this fails. | 
					
						
							| 
									
										
										
										
											2024-09-16 16:46:09 +00:00
										 |  |  | 	lists, err := p.state.DB.GetListsByAccountID(ctx, accountID) | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("db error getting lists for account %s: %w", accountID, err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	// Unprepare item from home + list timelines. | 
					
						
							|  |  |  | 	p.state.Caches.Timelines.Home.MustGet(accountID).UnprepareByStatusIDs(statusID) | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 	for _, list := range lists { | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 		p.state.Caches.Timelines.List.MustGet(list.ID).UnprepareByStatusIDs(statusID) | 
					
						
							| 
									
										
										
										
											2023-09-12 14:00:35 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } |