[performance] add caching of status fave, boost of, in reply to ID lists (#2060)

This commit is contained in:
kim 2023-08-04 12:28:33 +01:00 committed by GitHub
commit 9a291dea84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 610 additions and 406 deletions

View file

@ -19,16 +19,13 @@ package gtserror
import (
"errors"
"fmt"
)
// MultiError allows encapsulating multiple
// errors under a singular instance, which
// is useful when you only want to log on
// errors, not return early / bubble up.
type MultiError struct {
e []error
}
type MultiError []error
// NewMultiError returns a *MultiError with
// the capacity of its underlying error slice
@ -40,15 +37,13 @@ type MultiError struct {
//
// If you don't know in advance what the capacity
// must be, just use new(MultiError) instead.
func NewMultiError(capacity int) *MultiError {
return &MultiError{
e: make([]error, 0, capacity),
}
func NewMultiError(capacity int) MultiError {
return make([]error, 0, capacity)
}
// Append the given error to the MultiError.
func (m *MultiError) Append(err error) {
m.e = append(m.e, err)
(*m) = append((*m), err)
}
// Append the given format string to the MultiError.
@ -56,12 +51,13 @@ func (m *MultiError) Append(err error) {
// It is valid to use %w in the format string
// to wrap any other errors.
func (m *MultiError) Appendf(format string, args ...any) {
m.e = append(m.e, fmt.Errorf(format, args...))
err := newfAt(3, format, args...)
(*m) = append((*m), err)
}
// Combine the MultiError into a single error.
//
// Unwrap will work on the returned error as expected.
func (m MultiError) Combine() error {
return errors.Join(m.e...)
return errors.Join(m...)
}

View file

@ -15,22 +15,22 @@
// 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 gtserror
package gtserror_test
import (
"errors"
"testing"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
)
func TestMultiError(t *testing.T) {
errs := MultiError{
e: []error{
db.ErrNoEntries,
errors.New("oopsie woopsie we did a fucky wucky etc"),
},
}
errs := gtserror.MultiError([]error{
db.ErrNoEntries,
errors.New("oopsie woopsie we did a fucky wucky etc"),
})
errs.Appendf("appended + wrapped error: %w", db.ErrAlreadyExists)
err := errs.Combine()
@ -50,14 +50,14 @@ func TestMultiError(t *testing.T) {
errString := err.Error()
expected := `sql: no rows in result set
oopsie woopsie we did a fucky wucky etc
appended + wrapped error: already exists`
TestMultiError: appended + wrapped error: already exists`
if errString != expected {
t.Errorf("errString '%s' should be '%s'", errString, expected)
}
}
func TestMultiErrorEmpty(t *testing.T) {
err := new(MultiError).Combine()
err := new(gtserror.MultiError).Combine()
if err != nil {
t.Errorf("should be nil")
}