Skip to content

Commit

Permalink
refactor: speedup izrss entry
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelroses committed Aug 22, 2024
1 parent 4081b1b commit 95e6e03
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
50 changes: 29 additions & 21 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"log"
"sync"

"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -51,35 +52,42 @@ func (m Model) handleWindowSize(msg tea.WindowSizeMsg) Model {
log.Fatalf("could not read tracking file: %v", err)
}

var glamWidth glamour.TermRendererOption
switch lib.UserConfig.Reader.Size.(type) {
case string:
switch lib.UserConfig.Reader.Size {
case "full", "fullscreen":
glamWidth = glamour.WithWordWrap(width)
case "most":
glamWidth = glamour.WithWordWrap(int(float64(width) * 0.75))
case "recomended":
glamWidth = glamour.WithWordWrap(80)
// we make this part mutli-threaded otherwise its really slow
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
var glamWidth glamour.TermRendererOption
switch lib.UserConfig.Reader.Size.(type) {
case string:
switch lib.UserConfig.Reader.Size {
case "full", "fullscreen":
glamWidth = glamour.WithWordWrap(width)
case "most":
glamWidth = glamour.WithWordWrap(int(float64(width) * 0.75))
case "recomended":
glamWidth = glamour.WithWordWrap(80)
}

case int64:
w := int(lib.UserConfig.Reader.Size.(int64))
glamWidth = glamour.WithWordWrap(w)
default:
log.Fatalf("invalid reader size: %v", lib.UserConfig.Reader.Size)
}

case int64:
w := int(lib.UserConfig.Reader.Size.(int64))
glamWidth = glamour.WithWordWrap(w)
default:
log.Fatalf("invalid reader size: %v", lib.UserConfig.Reader.Size)
}
m.glam, _ = glamour.NewTermRenderer(
glamour.WithEnvironmentConfig(),
glamWidth,
)
m.glam, _ = glamour.NewTermRenderer(
glamour.WithEnvironmentConfig(),
glamWidth,
)
}()

if lib.UserConfig.Home == "mixed" {
m.loadMixed()
} else {
m.loadHome()
}

wg.Wait()
m.ready = true
} else {
m.viewport.Width = width
Expand Down
15 changes: 7 additions & 8 deletions lib/feeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,21 @@ func (f Feed) GetTotalUnreads() int {
// also a bit of nix inspired me to write this `foldl recursiveUpdate { } importedLibs`
// okay maybe it was beacuse of the comments not actually the code, kinda fair.
func mergeFeeds(feeds1, feeds2 Feeds) Feeds {
// Create a map to hold posts from feeds1 by their UUID for quick lookup
postMap := make(map[string]*Post)
// Create a map to hold posts' read state from feeds1 by their UUID for quick lookup
readStatusMap := make(map[string]bool)

// Iterate through feeds1 and map their posts by UUID
for i := range feeds1 {
for j := range feeds1[i].Posts {
postMap[feeds1[i].Posts[j].UUID] = &feeds1[i].Posts[j]
for _, feed := range feeds1 {
for _, post := range feed.Posts {
readStatusMap[post.UUID] = post.Read
}
}

// Iterate through feeds2 and merge their posts into feeds1 based on UUID
for i := range feeds2 {
for j := range feeds2[i].Posts {
if post1, exists := postMap[feeds2[i].Posts[j].UUID]; exists {
// Update the existing post in feeds1 with the one from feeds2
post1.Read = feeds2[i].Posts[j].Read
if readStatus, exists := readStatusMap[feeds1[i].Posts[j].UUID]; exists {
feeds1[i].Posts[j].Read = readStatus
}
}
}
Expand Down

0 comments on commit 95e6e03

Please sign in to comment.