From d7d9994c51e2b285813b9ebd0672013adcb16df1 Mon Sep 17 00:00:00 2001
From: chenthur <chenthurvelanganesan@gmail.com>
Date: Fri, 21 Jun 2024 14:27:57 +0100
Subject: [PATCH 1/3] unimportant

---
 src/reader/_app/__init__.py     |  2 +-
 src/reader/_storage/_entries.py |  7 ++++---
 src/reader/_storage/_search.py  |  2 +-
 src/reader/types.py             |  6 ++++++
 tests/test_reader_counts.py     | 14 ++++++++++++++
 tests/test_reader_search.py     |  6 +++---
 6 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/src/reader/_app/__init__.py b/src/reader/_app/__init__.py
index 0e1d0e48..a682dcfe 100644
--- a/src/reader/_app/__init__.py
+++ b/src/reader/_app/__init__.py
@@ -418,6 +418,7 @@ def add_entry():
 FEED_SORT_NATIVE = {'title', 'added'}
 FEED_SORT_FANCY = {
     'important': lambda counts: counts.important,
+    'unimportant':lambda counts: counts.unimportant,
     # TODO: an unread/unimportant property would be nice
     'unread': lambda counts: counts.total - counts.read,
     # TODO: if we keep these average intervals, properties for them might be nice too
@@ -435,7 +436,6 @@ def feeds():
 
     updates_enabled = request.args.get('updates-enabled')
     updates_enabled = {None: None, 'no': False, 'yes': True}[updates_enabled]
-
     sort = request.args.get('sort', 'title')
     assert sort in FEED_SORT_ALL
 
diff --git a/src/reader/_storage/_entries.py b/src/reader/_storage/_entries.py
index 325b2bc0..94fb6929 100644
--- a/src/reader/_storage/_entries.py
+++ b/src/reader/_storage/_entries.py
@@ -101,8 +101,9 @@ def get_entry_counts(
         context.update(new_context)
 
         row = exactly_one(self.get_db().execute(str(query), context))
-
-        return EntryCounts(*row[:4], row[4:7])  # type: ignore[call-arg]
+        print(row)
+        print(*row[:5], row[5:8])
+        return EntryCounts(*row[:5], row[5:8])  # type: ignore[call-arg]
 
     @wrap_exceptions()
     def set_entry_read(
@@ -593,6 +594,7 @@ def get_entry_counts_query(
             'count(*)',
             'coalesce(sum(read == 1), 0)',
             'coalesce(sum(important == 1), 0)',
+            'coalesce(sum(important == 0), 0)',
             """
             coalesce(
                 sum(
@@ -606,7 +608,6 @@ def get_entry_counts_query(
         .FROM("entries_filtered")
         .JOIN("entries USING (id, feed)")
     )
-
     # one CTE / period + HAVING in the CTE is a tiny bit faster than
     # one CTE + WHERE in the SELECT
 
diff --git a/src/reader/_storage/_search.py b/src/reader/_storage/_search.py
index b7851eb1..c1c9fa65 100644
--- a/src/reader/_storage/_search.py
+++ b/src/reader/_storage/_search.py
@@ -486,7 +486,7 @@ def search_entry_counts(
 
         context = dict(query=query, **query_context)
         row = exactly_one(self.get_db().execute(str(sql_query), context))
-        return EntrySearchCounts(*row[:4], row[4:7])  # type: ignore[call-arg]
+        return EntrySearchCounts(*row[:5], row[5:8])  # type: ignore[call-arg]
 
 
 def make_search_entries_query(
diff --git a/src/reader/types.py b/src/reader/types.py
index cdc1ce6c..361bfe5d 100644
--- a/src/reader/types.py
+++ b/src/reader/types.py
@@ -898,6 +898,9 @@ class EntryCounts(_namedtuple_compat):
     #: Number of important entries.
     important: int | None = None
 
+    #: Number of unimportant entries.
+    unimportant: int | None = None
+
     #: Number of entries that have enclosures.
     has_enclosures: int | None = None
 
@@ -935,6 +938,9 @@ class EntrySearchCounts(_namedtuple_compat):
     #: Number of important entries.
     important: int | None = None
 
+    #: Number of unimportant entries.
+    unimportant: int | None = None
+
     #: Number of entries that have enclosures.
     has_enclosures: int | None = None
 
diff --git a/tests/test_reader_counts.py b/tests/test_reader_counts.py
index 93281d00..8fb05144 100644
--- a/tests/test_reader_counts.py
+++ b/tests/test_reader_counts.py
@@ -66,6 +66,7 @@ def entries_per_day(month, quarter, year):
             9,
             read=2,
             important=4,
+            unimportant=0,
             has_enclosures=8,
             averages=entries_per_day(2, 3, 7),
         ),
@@ -76,6 +77,7 @@ def entries_per_day(month, quarter, year):
             1,
             read=0,
             important=0,
+            unimportant=0,
             has_enclosures=0,
             averages=entries_per_day(0, 0, 1),
         ),
@@ -86,6 +88,7 @@ def entries_per_day(month, quarter, year):
             8,
             read=2,
             important=4,
+            unimportant=0,
             has_enclosures=8,
             averages=entries_per_day(2, 3, 6),
         ),
@@ -96,6 +99,7 @@ def entries_per_day(month, quarter, year):
             1,
             read=0,
             important=0,
+            unimportant=0,
             has_enclosures=0,
             averages=entries_per_day(0, 0, 1),
         ),
@@ -106,6 +110,7 @@ def entries_per_day(month, quarter, year):
             1,
             read=1,
             important=1,
+            unimportant=0,
             has_enclosures=1,
             averages=entries_per_day(0, 0, 0),
         ),
@@ -116,6 +121,7 @@ def entries_per_day(month, quarter, year):
             1,
             read=0,
             important=1,
+            unimportant=0,
             has_enclosures=1,
             averages=entries_per_day(0, 0, 1),
         ),
@@ -126,6 +132,7 @@ def entries_per_day(month, quarter, year):
             1,
             read=0,
             important=0,
+            unimportant=0,
             has_enclosures=1,
             averages=entries_per_day(0, 0, 1),
         ),
@@ -136,6 +143,7 @@ def entries_per_day(month, quarter, year):
             2,
             read=2,
             important=2,
+            unimportant=0,
             has_enclosures=2,
             averages=entries_per_day(1, 1, 1),
         ),
@@ -146,6 +154,7 @@ def entries_per_day(month, quarter, year):
             7,
             read=0,
             important=2,
+            unimportant=0,
             has_enclosures=6,
             averages=entries_per_day(1, 2, 6),
         ),
@@ -156,6 +165,7 @@ def entries_per_day(month, quarter, year):
             4,
             read=2,
             important=4,
+            unimportant=0,
             has_enclosures=4,
             averages=entries_per_day(1, 1, 2),
         ),
@@ -166,6 +176,7 @@ def entries_per_day(month, quarter, year):
             5,
             read=0,
             important=0,
+            unimportant=0,
             has_enclosures=4,
             averages=entries_per_day(1, 2, 5),
         ),
@@ -176,6 +187,7 @@ def entries_per_day(month, quarter, year):
             8,
             read=2,
             important=4,
+            unimportant=0,
             has_enclosures=8,
             averages=entries_per_day(2, 3, 6),
         ),
@@ -186,6 +198,7 @@ def entries_per_day(month, quarter, year):
             1,
             read=0,
             important=0,
+            unimportant=0,
             has_enclosures=0,
             averages=entries_per_day(0, 0, 1),
         ),
@@ -196,6 +209,7 @@ def entries_per_day(month, quarter, year):
             1,
             read=0,
             important=0,
+            unimportant=0,
             has_enclosures=0,
             averages=entries_per_day(0, 0, 1),
         ),
diff --git a/tests/test_reader_search.py b/tests/test_reader_search.py
index cde2ece4..c1544478 100644
--- a/tests/test_reader_search.py
+++ b/tests/test_reader_search.py
@@ -600,7 +600,7 @@ def test_search_entries_basic(reader, sort):
     # TODO: the asserts below look parametrizable
 
     assert list(search('zero')) == []
-    assert search_counts('zero') == EntrySearchCounts(0, 0, 0, 0, (0, 0, 0))
+    assert search_counts('zero') == EntrySearchCounts(0, 0, 0, 0, 0, (0, 0, 0))
     assert list(search('one')) == [
         EntrySearchResult(
             feed.url,
@@ -611,7 +611,7 @@ def test_search_entries_basic(reader, sort):
             },
         )
     ]
-    assert search_counts('one') == EntrySearchCounts(1, 0, 0, 0, (0, 0, 0))
+    assert search_counts('one') == EntrySearchCounts(1, 0, 0, 0,0,(0, 0, 0))
     assert list(search('two')) == [
         EntrySearchResult(
             feed.url,
@@ -684,7 +684,7 @@ def test_search_entries_basic(reader, sort):
             ),
         ]
     }
-    assert search_counts('summary') == EntrySearchCounts(3, 0, 0, 0, (0, 0, 0))
+    assert search_counts('summary') == EntrySearchCounts(3, 0, 0, 0, 0,(0, 0, 0))
 
 
 # search_entries() filtering is tested in test_reader.py::test_entries_filtering{,_error}

From fdcab319654c4e1c9f95f08781d8f0425f1db094 Mon Sep 17 00:00:00 2001
From: chenthur <chenthurvelanganesan@gmail.com>
Date: Fri, 21 Jun 2024 14:34:07 +0100
Subject: [PATCH 2/3] update

---
 src/reader/_app/__init__.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/reader/_app/__init__.py b/src/reader/_app/__init__.py
index a682dcfe..6b20f401 100644
--- a/src/reader/_app/__init__.py
+++ b/src/reader/_app/__init__.py
@@ -419,7 +419,6 @@ def add_entry():
 FEED_SORT_FANCY = {
     'important': lambda counts: counts.important,
     'unimportant':lambda counts: counts.unimportant,
-    # TODO: an unread/unimportant property would be nice
     'unread': lambda counts: counts.total - counts.read,
     # TODO: if we keep these average intervals, properties for them might be nice too
     'avg1m': lambda counts: counts.averages[0],

From 046411ea64e4110f69846e51bfa81185641e1fae Mon Sep 17 00:00:00 2001
From: chenthur <chenthurvelanganesan@gmail.com>
Date: Fri, 21 Jun 2024 14:36:47 +0100
Subject: [PATCH 3/3] update

---
 src/reader/_storage/_entries.py | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/reader/_storage/_entries.py b/src/reader/_storage/_entries.py
index 94fb6929..878d6582 100644
--- a/src/reader/_storage/_entries.py
+++ b/src/reader/_storage/_entries.py
@@ -101,8 +101,6 @@ def get_entry_counts(
         context.update(new_context)
 
         row = exactly_one(self.get_db().execute(str(query), context))
-        print(row)
-        print(*row[:5], row[5:8])
         return EntryCounts(*row[:5], row[5:8])  # type: ignore[call-arg]
 
     @wrap_exceptions()