diff options
author | 2021-08-10 13:32:39 +0200 | |
---|---|---|
committer | 2021-08-10 13:32:39 +0200 | |
commit | 0f2de6394a1c52d47e326bb7d7d129a217ae4f6f (patch) | |
tree | e2709bdbbbbcf5e12d6da62b653b67f1789ab1c5 /internal/db | |
parent | Frodo swaggins (#126) (diff) | |
download | gotosocial-0f2de6394a1c52d47e326bb7d7d129a217ae4f6f.tar.xz |
Dereference remote replies (#132)
* decided where to put reply dereferencing
* fiddling with dereferencing threads
* further adventures
* tidy up some stuff
* move dereferencing functionality
* a bunch of refactoring
* go fmt
* more refactoring
* bleep bloop
* docs and linting
* start implementing replies collection on gts side
* fiddling around
* allow dereferencing our replies
* lint, fmt
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/db.go | 8 | ||||
-rw-r--r-- | internal/db/pg/statuscontext.go | 31 |
2 files changed, 27 insertions, 12 deletions
diff --git a/internal/db/db.go b/internal/db/db.go index c764cc716..d0b23fbc6 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -218,10 +218,14 @@ type DB interface { GetFaveCountForStatus(status *gtsmodel.Status) (int, error) // StatusParents get the parent statuses of a given status. - StatusParents(status *gtsmodel.Status) ([]*gtsmodel.Status, error) + // + // If onlyDirect is true, only the immediate parent will be returned. + StatusParents(status *gtsmodel.Status, onlyDirect bool) ([]*gtsmodel.Status, error) // StatusChildren gets the child statuses of a given status. - StatusChildren(status *gtsmodel.Status) ([]*gtsmodel.Status, error) + // + // If onlyDirect is true, only the immediate children will be returned. + StatusChildren(status *gtsmodel.Status, onlyDirect bool, minID string) ([]*gtsmodel.Status, error) // StatusFavedBy checks if a given status has been faved by a given account ID StatusFavedBy(status *gtsmodel.Status, accountID string) (bool, error) diff --git a/internal/db/pg/statuscontext.go b/internal/db/pg/statuscontext.go index 732485ab5..2ff1a20bb 100644 --- a/internal/db/pg/statuscontext.go +++ b/internal/db/pg/statuscontext.go @@ -25,14 +25,14 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (ps *postgresService) StatusParents(status *gtsmodel.Status) ([]*gtsmodel.Status, error) { +func (ps *postgresService) StatusParents(status *gtsmodel.Status, onlyDirect bool) ([]*gtsmodel.Status, error) { parents := []*gtsmodel.Status{} - ps.statusParent(status, &parents) + ps.statusParent(status, &parents, onlyDirect) return parents, nil } -func (ps *postgresService) statusParent(status *gtsmodel.Status, foundStatuses *[]*gtsmodel.Status) { +func (ps *postgresService) statusParent(status *gtsmodel.Status, foundStatuses *[]*gtsmodel.Status, onlyDirect bool) { if status.InReplyToID == "" { return } @@ -42,13 +42,16 @@ func (ps *postgresService) statusParent(status *gtsmodel.Status, foundStatuses * *foundStatuses = append(*foundStatuses, parentStatus) } - ps.statusParent(parentStatus, foundStatuses) + if onlyDirect { + return + } + ps.statusParent(parentStatus, foundStatuses, false) } -func (ps *postgresService) StatusChildren(status *gtsmodel.Status) ([]*gtsmodel.Status, error) { +func (ps *postgresService) StatusChildren(status *gtsmodel.Status, onlyDirect bool, minID string) ([]*gtsmodel.Status, error) { foundStatuses := &list.List{} foundStatuses.PushFront(status) - ps.statusChildren(status, foundStatuses) + ps.statusChildren(status, foundStatuses, onlyDirect, minID) children := []*gtsmodel.Status{} for e := foundStatuses.Front(); e != nil; e = e.Next() { @@ -66,11 +69,15 @@ func (ps *postgresService) StatusChildren(status *gtsmodel.Status) ([]*gtsmodel. return children, nil } -func (ps *postgresService) statusChildren(status *gtsmodel.Status, foundStatuses *list.List) { +func (ps *postgresService) statusChildren(status *gtsmodel.Status, foundStatuses *list.List, onlyDirect bool, minID string) { immediateChildren := []*gtsmodel.Status{} - err := ps.conn.Model(&immediateChildren).Where("in_reply_to_id = ?", status.ID).Select() - if err != nil { + q := ps.conn.Model(&immediateChildren).Where("in_reply_to_id = ?", status.ID) + if minID != "" { + q = q.Where("status.id > ?", minID) + } + + if err := q.Select(); err != nil { return } @@ -88,6 +95,10 @@ func (ps *postgresService) statusChildren(status *gtsmodel.Status, foundStatuses } } - ps.statusChildren(child, foundStatuses) + // only do one loop if we only want direct children + if onlyDirect { + return + } + ps.statusChildren(child, foundStatuses, false, minID) } } |