mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-02 04:22:25 -06:00
[bugfix] update thread iterators to not use recursion (#851)
* update thread iterators to not use recursion, rewrote both Signed-off-by: kim <grufwub@gmail.com> * fix endless descendant deref, don't error if fetching existing status Signed-off-by: kim <grufwub@gmail.com> * don't refetch remote ancestor statuses, improve descendant iter commenting Signed-off-by: kim <grufwub@gmail.com> * move collection page next logic so we capture first page of entities Signed-off-by: kim <grufwub@gmail.com> * improve log format argument quoting Signed-off-by: kim <grufwub@gmail.com> * improve code commenting of collection paging Signed-off-by: kim <grufwub@gmail.com> * only dereference announce's originating status if _not_ local. update DereferenceThread() signature. cleanup searchStatusByURI() Signed-off-by: kim <grufwub@gmail.com> Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
78409f1985
commit
7a1aa04bbb
7 changed files with 299 additions and 203 deletions
|
|
@ -24,31 +24,50 @@ import (
|
|||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
|
||||
func (d *deref) DereferenceAnnounce(ctx context.Context, announce *gtsmodel.Status, requestingUsername string) error {
|
||||
if announce.BoostOf == nil || announce.BoostOf.URI == "" {
|
||||
if announce.BoostOf == nil {
|
||||
// we can't do anything unfortunately
|
||||
return errors.New("DereferenceAnnounce: no URI to dereference")
|
||||
}
|
||||
|
||||
boostedStatusURI, err := url.Parse(announce.BoostOf.URI)
|
||||
// Parse the boosted status' URI
|
||||
boostedURI, err := url.Parse(announce.BoostOf.URI)
|
||||
if err != nil {
|
||||
return fmt.Errorf("DereferenceAnnounce: couldn't parse boosted status URI %s: %s", announce.BoostOf.URI, err)
|
||||
}
|
||||
if blocked, err := d.db.IsDomainBlocked(ctx, boostedStatusURI.Host); blocked || err != nil {
|
||||
return fmt.Errorf("DereferenceAnnounce: domain %s is blocked", boostedStatusURI.Host)
|
||||
|
||||
// Check whether the originating status is from a blocked host
|
||||
if blocked, err := d.db.IsDomainBlocked(ctx, boostedURI.Host); blocked || err != nil {
|
||||
return fmt.Errorf("DereferenceAnnounce: domain %s is blocked", boostedURI.Host)
|
||||
}
|
||||
|
||||
// dereference statuses in the thread of the boosted status
|
||||
if err := d.DereferenceThread(ctx, requestingUsername, boostedStatusURI); err != nil {
|
||||
return fmt.Errorf("DereferenceAnnounce: error dereferencing thread of boosted status: %s", err)
|
||||
}
|
||||
var boostedStatus *gtsmodel.Status
|
||||
|
||||
boostedStatus, _, err := d.GetRemoteStatus(ctx, requestingUsername, boostedStatusURI, false, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("DereferenceAnnounce: error dereferencing remote status with id %s: %s", announce.BoostOf.URI, err)
|
||||
if boostedURI.Host == config.GetHost() {
|
||||
// This is a local status, fetch from the database
|
||||
status, err := d.db.GetStatusByURI(ctx, boostedURI.String())
|
||||
if err != nil {
|
||||
return fmt.Errorf("DereferenceAnnounce: error fetching local status %q: %v", announce.BoostOf.URI, err)
|
||||
}
|
||||
|
||||
// Set boosted status
|
||||
boostedStatus = status
|
||||
} else {
|
||||
// This is a boost of a remote status, we need to dereference it.
|
||||
status, statusable, err := d.GetRemoteStatus(ctx, requestingUsername, boostedURI, true, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("DereferenceAnnounce: error dereferencing remote status with id %s: %s", announce.BoostOf.URI, err)
|
||||
}
|
||||
|
||||
// Dereference all statuses in the thread of the boosted status
|
||||
d.DereferenceThread(ctx, requestingUsername, boostedURI, status, statusable)
|
||||
|
||||
// Set boosted status
|
||||
boostedStatus = status
|
||||
}
|
||||
|
||||
announce.Content = boostedStatus.Content
|
||||
|
|
@ -65,5 +84,6 @@ func (d *deref) DereferenceAnnounce(ctx context.Context, announce *gtsmodel.Stat
|
|||
announce.Replyable = boostedStatus.Replyable
|
||||
announce.Likeable = boostedStatus.Likeable
|
||||
announce.BoostOf = boostedStatus
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue