aboutsummaryrefslogtreecommitdiff
path: root/cmds/relabel.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmds/relabel.go')
-rw-r--r--cmds/relabel.go42
1 files changed, 35 insertions, 7 deletions
diff --git a/cmds/relabel.go b/cmds/relabel.go
index 9233daf..3411b0d 100644
--- a/cmds/relabel.go
+++ b/cmds/relabel.go
@@ -28,22 +28,50 @@ import (
"fluxrec/core"
)
+// starsByKey is this run's stars, each with the moment the star happened.
+// Keyed by entry ID and by normalized URL, because a star on a rec-feed item
+// is only tied to the original row by its URL.
+type starsByKey struct {
+ byID map[int64]time.Time
+ byURL map[string]time.Time
+}
+
+func (s *starsByKey) add(id int64, url string, at time.Time) {
+ if s.byID == nil {
+ s.byID = make(map[int64]time.Time)
+ s.byURL = make(map[string]time.Time)
+ }
+ s.byID[id] = at
+ s.byURL[core.NormalizeURL(url)] = at
+}
+
+// stamp returns when the row's entry was starred, if it was.
+func (s starsByKey) stamp(row core.LabelRow) (time.Time, bool) {
+ if t, ok := s.byID[row.EntryID]; ok {
+ return t, true
+ }
+ if t, ok := s.byURL[core.NormalizeURL(row.URL)]; ok {
+ return t, true
+ }
+ return time.Time{}, false
+}
+
// relabelStars flips negative rows to positives for entries starred since they
-// were labeled. ids and urls are this run's stars: entry IDs as seen on the
-// starred entries, and normalized URLs (which is how a star on a rec-feed item
-// resolves to the original row). Rows are mutated in place; the count of
-// flipped rows is returned.
-func relabelStars(rows []core.LabelRow, ids map[int64]bool, urls map[string]bool, now time.Time) int {
+// were labeled, stamping each with the star's own time (falling back to the
+// run clock when a row's star time is unknown). Rows are mutated in place; the
+// count of flipped rows is returned.
+func relabelStars(rows []core.LabelRow, stars starsByKey, now time.Time) int {
flipped := 0
for i := range rows {
if rows[i].Label != core.LabelNeg {
continue
}
- if !ids[rows[i].EntryID] && !urls[core.NormalizeURL(rows[i].URL)] {
+ at, ok := stars.stamp(rows[i])
+ if !ok {
continue
}
rows[i].Label = core.LabelPos
- rows[i].CapturedAt = now
+ rows[i].CapturedAt = at
flipped++
}
return flipped