mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-16 21:07:29 -06:00
[bugfix/chore] Refactor timeline code (#1656)
* start poking timelines * OK yes we're refactoring, but it's nothing like the last time so don't worry * more fiddling * update tests, simplify Get * thanks linter, you're the best, mwah mwah kisses * do a bit more tidying up * start buggering about with the prepare function * fix little oopsie * start merging lists into 1 * ik heb een heel zwaar leven nee nee echt waar * hey it works we did it reddit * regenerate swagger docs * tidy up a wee bit * adjust paging * fix little error, remove unused functions
This commit is contained in:
parent
c54510bc74
commit
3510454768
22 changed files with 1319 additions and 1365 deletions
|
|
@ -20,7 +20,6 @@ package timeline
|
|||
import (
|
||||
"container/list"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"codeberg.org/gruf/go-kv"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
|
|
@ -35,52 +34,35 @@ func (t *timeline) Remove(ctx context.Context, statusID string) (int, error) {
|
|||
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
var removed int
|
||||
|
||||
// remove entr(ies) from the post index
|
||||
removeIndexes := []*list.Element{}
|
||||
if t.indexedItems != nil && t.indexedItems.data != nil {
|
||||
for e := t.indexedItems.data.Front(); e != nil; e = e.Next() {
|
||||
entry, ok := e.Value.(*indexedItemsEntry)
|
||||
if !ok {
|
||||
return removed, errors.New("Remove: could not parse e as a postIndexEntry")
|
||||
}
|
||||
if entry.itemID == statusID {
|
||||
l.Debug("found status in postIndex")
|
||||
removeIndexes = append(removeIndexes, e)
|
||||
}
|
||||
if t.items == nil || t.items.data == nil {
|
||||
// Nothing to do.
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var toRemove []*list.Element
|
||||
for e := t.items.data.Front(); e != nil; e = e.Next() {
|
||||
entry := e.Value.(*indexedItemsEntry) // nolint:forcetypeassert
|
||||
|
||||
if entry.itemID != statusID {
|
||||
// Not relevant.
|
||||
continue
|
||||
}
|
||||
}
|
||||
for _, e := range removeIndexes {
|
||||
t.indexedItems.data.Remove(e)
|
||||
removed++
|
||||
|
||||
l.Debug("removing item")
|
||||
toRemove = append(toRemove, e)
|
||||
}
|
||||
|
||||
// remove entr(ies) from prepared posts
|
||||
removePrepared := []*list.Element{}
|
||||
if t.preparedItems != nil && t.preparedItems.data != nil {
|
||||
for e := t.preparedItems.data.Front(); e != nil; e = e.Next() {
|
||||
entry, ok := e.Value.(*preparedItemsEntry)
|
||||
if !ok {
|
||||
return removed, errors.New("Remove: could not parse e as a preparedPostsEntry")
|
||||
}
|
||||
if entry.itemID == statusID {
|
||||
l.Debug("found status in preparedPosts")
|
||||
removePrepared = append(removePrepared, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, e := range removePrepared {
|
||||
t.preparedItems.data.Remove(e)
|
||||
removed++
|
||||
for _, e := range toRemove {
|
||||
t.items.data.Remove(e)
|
||||
}
|
||||
|
||||
l.Debugf("removed %d entries", removed)
|
||||
return removed, nil
|
||||
return len(toRemove), nil
|
||||
}
|
||||
|
||||
func (t *timeline) RemoveAllBy(ctx context.Context, accountID string) (int, error) {
|
||||
l := log.WithContext(ctx).
|
||||
func (t *timeline) RemoveAllByOrBoosting(ctx context.Context, accountID string) (int, error) {
|
||||
l := log.
|
||||
WithContext(ctx).
|
||||
WithFields(kv.Fields{
|
||||
{"accountTimeline", t.accountID},
|
||||
{"accountID", accountID},
|
||||
|
|
@ -88,46 +70,28 @@ func (t *timeline) RemoveAllBy(ctx context.Context, accountID string) (int, erro
|
|||
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
var removed int
|
||||
|
||||
// remove entr(ies) from the post index
|
||||
removeIndexes := []*list.Element{}
|
||||
if t.indexedItems != nil && t.indexedItems.data != nil {
|
||||
for e := t.indexedItems.data.Front(); e != nil; e = e.Next() {
|
||||
entry, ok := e.Value.(*indexedItemsEntry)
|
||||
if !ok {
|
||||
return removed, errors.New("Remove: could not parse e as a postIndexEntry")
|
||||
}
|
||||
if entry.accountID == accountID || entry.boostOfAccountID == accountID {
|
||||
l.Debug("found status in postIndex")
|
||||
removeIndexes = append(removeIndexes, e)
|
||||
}
|
||||
if t.items == nil || t.items.data == nil {
|
||||
// Nothing to do.
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var toRemove []*list.Element
|
||||
for e := t.items.data.Front(); e != nil; e = e.Next() {
|
||||
entry := e.Value.(*indexedItemsEntry) // nolint:forcetypeassert
|
||||
|
||||
if entry.accountID != accountID && entry.boostOfAccountID != accountID {
|
||||
// Not relevant.
|
||||
continue
|
||||
}
|
||||
}
|
||||
for _, e := range removeIndexes {
|
||||
t.indexedItems.data.Remove(e)
|
||||
removed++
|
||||
|
||||
l.Debug("removing item")
|
||||
toRemove = append(toRemove, e)
|
||||
}
|
||||
|
||||
// remove entr(ies) from prepared posts
|
||||
removePrepared := []*list.Element{}
|
||||
if t.preparedItems != nil && t.preparedItems.data != nil {
|
||||
for e := t.preparedItems.data.Front(); e != nil; e = e.Next() {
|
||||
entry, ok := e.Value.(*preparedItemsEntry)
|
||||
if !ok {
|
||||
return removed, errors.New("Remove: could not parse e as a preparedPostsEntry")
|
||||
}
|
||||
if entry.accountID == accountID || entry.boostOfAccountID == accountID {
|
||||
l.Debug("found status in preparedPosts")
|
||||
removePrepared = append(removePrepared, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, e := range removePrepared {
|
||||
t.preparedItems.data.Remove(e)
|
||||
removed++
|
||||
for _, e := range toRemove {
|
||||
t.items.data.Remove(e)
|
||||
}
|
||||
|
||||
l.Debugf("removed %d entries", removed)
|
||||
return removed, nil
|
||||
return len(toRemove), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue