Browse Source

pub/post: Parents(0) is used to prevent a microload that determines if there are any parents

Benton Edmondson 1 year ago
parent
commit
e8ac942356
2 changed files with 8 additions and 3 deletions
  1. 4 1
      pub/post.go
  2. 4 2
      ui/ui.go

+ 4 - 1
pub/post.go

@@ -145,7 +145,10 @@ func (p *Post) Children() Container {
 
 func (p *Post) Parents(quantity uint) ([]Tangible, Tangible) {
 	if quantity == 0 {
-		panic("can't fetch zero parents")
+		if errors.Is(p.parentErr, object.ErrKeyNotPresent) {
+			return []Tangible{}, nil
+		}
+		return []Tangible{}, p
 	}
 	if errors.Is(p.parentErr, object.ErrKeyNotPresent) {
 		return []Tangible{}, nil

+ 4 - 2
ui/ui.go

@@ -311,10 +311,11 @@ func (s *State) switchTo(item any) {
 			return
 		}
 		if len(narrowed) == 1 {
+			_, frontier := narrowed[0].Parents(0)
 			s.h.Add(&Page{
 				feed:     feed.Create(narrowed[0]),
 				children: narrowed[0].Children(),
-				frontier: narrowed[0],
+				frontier: frontier,
 			})
 		} else {
 			s.h.Add(&Page{
@@ -322,10 +323,11 @@ func (s *State) switchTo(item any) {
 			})
 		}
 	case pub.Tangible:
+		_, frontier := narrowed.Parents(0)
 		s.h.Add(&Page{
 			feed:     feed.Create(narrowed),
 			children: narrowed.Children(),
-			frontier: narrowed,
+			frontier: frontier,
 		})
 	case pub.Container:
 		if s.mode != loading {