From 6a6a4993338262f87df34c9be051bfaac75c1829 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Sat, 26 Apr 2025 09:56:15 +0000 Subject: [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 --- vendor/codeberg.org/gruf/go-bytes/bytes.go | 261 ----------------------------- 1 file changed, 261 deletions(-) delete mode 100644 vendor/codeberg.org/gruf/go-bytes/bytes.go (limited to 'vendor/codeberg.org/gruf/go-bytes/bytes.go') diff --git a/vendor/codeberg.org/gruf/go-bytes/bytes.go b/vendor/codeberg.org/gruf/go-bytes/bytes.go deleted file mode 100644 index 5fef75d56..000000000 --- a/vendor/codeberg.org/gruf/go-bytes/bytes.go +++ /dev/null @@ -1,261 +0,0 @@ -package bytes - -import ( - "bytes" - "reflect" - "unsafe" -) - -var ( - _ Bytes = &Buffer{} - _ Bytes = bytesType{} -) - -// Bytes defines a standard way of retrieving the content of a -// byte buffer of some-kind. -type Bytes interface { - // Bytes returns the byte slice content - Bytes() []byte - - // String returns byte slice cast directly to string, this - // will cause an allocation but comes with the safety of - // being an immutable Go string - String() string - - // StringPtr returns byte slice cast to string via the unsafe - // package. This comes with the same caveats of accessing via - // .Bytes() in that the content is liable change and is NOT - // immutable, despite being a string type - StringPtr() string -} - -type bytesType []byte - -func (b bytesType) Bytes() []byte { - return b -} - -func (b bytesType) String() string { - return string(b) -} - -func (b bytesType) StringPtr() string { - return BytesToString(b) -} - -// ToBytes casts the provided byte slice as the simplest possible -// Bytes interface implementation -func ToBytes(b []byte) Bytes { - return bytesType(b) -} - -// Copy returns a new copy of slice b, does NOT maintain nil values -func Copy(b []byte) []byte { - p := make([]byte, len(b)) - copy(p, b) - return p -} - -// BytesToString returns byte slice cast to string via the "unsafe" package -func BytesToString(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) -} - -// StringToBytes returns the string cast to string via the "unsafe" and "reflect" packages -func StringToBytes(s string) []byte { - // thank you to https://github.com/valyala/fasthttp/blob/master/bytesconv.go - var b []byte - - // Get byte + string headers - bh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) - sh := (*reflect.StringHeader)(unsafe.Pointer(&s)) - - // Manually set bytes to string - bh.Data = sh.Data - bh.Len = sh.Len - bh.Cap = sh.Len - - return b -} - -// // InsertByte inserts the supplied byte into the slice at provided position -// func InsertByte(b []byte, at int, c byte) []byte { -// return append(append(b[:at], c), b[at:]...) -// } - -// // Insert inserts the supplied byte slice into the slice at provided position -// func Insert(b []byte, at int, s []byte) []byte { -// return append(append(b[:at], s...), b[at:]...) -// } - -// ToUpper offers a faster ToUpper implementation using a lookup table -func ToUpper(b []byte) { - for i := 0; i < len(b); i++ { - c := &b[i] - *c = toUpperTable[*c] - } -} - -// ToLower offers a faster ToLower implementation using a lookup table -func ToLower(b []byte) { - for i := 0; i < len(b); i++ { - c := &b[i] - *c = toLowerTable[*c] - } -} - -// HasBytePrefix returns whether b has the provided byte prefix -func HasBytePrefix(b []byte, c byte) bool { - return (len(b) > 0) && (b[0] == c) -} - -// HasByteSuffix returns whether b has the provided byte suffix -func HasByteSuffix(b []byte, c byte) bool { - return (len(b) > 0) && (b[len(b)-1] == c) -} - -// HasBytePrefix returns b without the provided leading byte -func TrimBytePrefix(b []byte, c byte) []byte { - if HasBytePrefix(b, c) { - return b[1:] - } - return b -} - -// TrimByteSuffix returns b without the provided trailing byte -func TrimByteSuffix(b []byte, c byte) []byte { - if HasByteSuffix(b, c) { - return b[:len(b)-1] - } - return b -} - -// Compare is a direct call-through to standard library bytes.Compare() -func Compare(b, s []byte) int { - return bytes.Compare(b, s) -} - -// Contains is a direct call-through to standard library bytes.Contains() -func Contains(b, s []byte) bool { - return bytes.Contains(b, s) -} - -// TrimPrefix is a direct call-through to standard library bytes.TrimPrefix() -func TrimPrefix(b, s []byte) []byte { - return bytes.TrimPrefix(b, s) -} - -// TrimSuffix is a direct call-through to standard library bytes.TrimSuffix() -func TrimSuffix(b, s []byte) []byte { - return bytes.TrimSuffix(b, s) -} - -// Equal is a direct call-through to standard library bytes.Equal() -func Equal(b, s []byte) bool { - return bytes.Equal(b, s) -} - -// EqualFold is a direct call-through to standard library bytes.EqualFold() -func EqualFold(b, s []byte) bool { - return bytes.EqualFold(b, s) -} - -// Fields is a direct call-through to standard library bytes.Fields() -func Fields(b []byte) [][]byte { - return bytes.Fields(b) -} - -// FieldsFunc is a direct call-through to standard library bytes.FieldsFunc() -func FieldsFunc(b []byte, fn func(rune) bool) [][]byte { - return bytes.FieldsFunc(b, fn) -} - -// HasPrefix is a direct call-through to standard library bytes.HasPrefix() -func HasPrefix(b, s []byte) bool { - return bytes.HasPrefix(b, s) -} - -// HasSuffix is a direct call-through to standard library bytes.HasSuffix() -func HasSuffix(b, s []byte) bool { - return bytes.HasSuffix(b, s) -} - -// Index is a direct call-through to standard library bytes.Index() -func Index(b, s []byte) int { - return bytes.Index(b, s) -} - -// IndexByte is a direct call-through to standard library bytes.IndexByte() -func IndexByte(b []byte, c byte) int { - return bytes.IndexByte(b, c) -} - -// IndexAny is a direct call-through to standard library bytes.IndexAny() -func IndexAny(b []byte, s string) int { - return bytes.IndexAny(b, s) -} - -// IndexRune is a direct call-through to standard library bytes.IndexRune() -func IndexRune(b []byte, r rune) int { - return bytes.IndexRune(b, r) -} - -// IndexFunc is a direct call-through to standard library bytes.IndexFunc() -func IndexFunc(b []byte, fn func(rune) bool) int { - return bytes.IndexFunc(b, fn) -} - -// LastIndex is a direct call-through to standard library bytes.LastIndex() -func LastIndex(b, s []byte) int { - return bytes.LastIndex(b, s) -} - -// LastIndexByte is a direct call-through to standard library bytes.LastIndexByte() -func LastIndexByte(b []byte, c byte) int { - return bytes.LastIndexByte(b, c) -} - -// LastIndexAny is a direct call-through to standard library bytes.LastIndexAny() -func LastIndexAny(b []byte, s string) int { - return bytes.LastIndexAny(b, s) -} - -// LastIndexFunc is a direct call-through to standard library bytes.LastIndexFunc() -func LastIndexFunc(b []byte, fn func(rune) bool) int { - return bytes.LastIndexFunc(b, fn) -} - -// Replace is a direct call-through to standard library bytes.Replace() -func Replace(b, s, r []byte, c int) []byte { - return bytes.Replace(b, s, r, c) -} - -// ReplaceAll is a direct call-through to standard library bytes.ReplaceAll() -func ReplaceAll(b, s, r []byte) []byte { - return bytes.ReplaceAll(b, s, r) -} - -// Split is a direct call-through to standard library bytes.Split() -func Split(b, s []byte) [][]byte { - return bytes.Split(b, s) -} - -// SplitAfter is a direct call-through to standard library bytes.SplitAfter() -func SplitAfter(b, s []byte) [][]byte { - return bytes.SplitAfter(b, s) -} - -// SplitN is a direct call-through to standard library bytes.SplitN() -func SplitN(b, s []byte, c int) [][]byte { - return bytes.SplitN(b, s, c) -} - -// SplitAfterN is a direct call-through to standard library bytes.SplitAfterN() -func SplitAfterN(b, s []byte, c int) [][]byte { - return bytes.SplitAfterN(b, s, c) -} - -// NewReader is a direct call-through to standard library bytes.NewReader() -func NewReader(b []byte) *bytes.Reader { - return bytes.NewReader(b) -} -- cgit v1.2.3