This is an automated email from the ASF dual-hosted git repository.

gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git

commit 2b10e79ce4de5f6e58df1bc4bdd8072b8a10a3a9
Author: Greg Stein <[email protected]>
AuthorDate: Sun Feb 22 00:05:48 2026 -0600

    feat: add queries and method to list closed and open election IDs
    
    Co-authored-by: aider (openrouter/x-ai/grok-code-fast-1) <[email protected]>
---
 v3/queries.yaml        |  5 ++++-
 v3/server/bin/tally.py | 14 +++++---------
 v3/steve/election.py   | 15 +++++++++++++++
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/v3/queries.yaml b/v3/queries.yaml
index 12ce8cc..6efd088 100644
--- a/v3/queries.yaml
+++ b/v3/queries.yaml
@@ -40,7 +40,7 @@ election:
     c_add_issue: INSERT INTO issue VALUES (?, ?, ?, ?, ?, ?)
     c_edit_issue: |
         UPDATE issue
-        SET title = ?, description = ?, type = ?, kv = ?
+        SET title = ?, description, type = ?, kv = ?
         WHERE iid = ?
     c_delete_issue: DELETE FROM issue WHERE iid = ?
     c_add_vote: |
@@ -167,6 +167,9 @@ election:
         WHERE i.eid = ?
         ORDER BY m.pid
 
+    q_closed_election_ids: SELECT eid FROM election WHERE closed = 1
+    q_open_election_ids: SELECT eid FROM election WHERE salt IS NOT NULL AND 
(closed IS NULL OR closed = 0)
+
 person:
     c_add_person: |
         INSERT INTO person VALUES (?, ?, ?)
diff --git a/v3/server/bin/tally.py b/v3/server/bin/tally.py
index baec8d2..4185a23 100755
--- a/v3/server/bin/tally.py
+++ b/v3/server/bin/tally.py
@@ -39,17 +39,13 @@ def list_elections(db_fname, spy_on_open):
     Returns a list of (eid, title, close_at, state) tuples, sorted by close_at 
descending.
     Includes closed elections, or open ones if spy_on_open is True.
     """
-    # Get all elections owned by a dummy PID (since owned_elections doesn't 
filter by state)
-    # This is a hack; ideally, add a query for all elections with states.
-    # For now, fetch all owned by a non-existent PID to get all elections.
-    all_elections = steve.election.Election.owned_elections(db_fname, 
'dummy_pid')
+    eids = steve.election.Election.list_closed_election_ids(db_fname, 
include_open=spy_on_open)
     
     elections = []
-    for e in all_elections:
-        election = steve.election.Election(db_fname, e.eid)
-        state = election.get_state()
-        if state == steve.election.Election.S_CLOSED or (spy_on_open and state 
== steve.election.Election.S_OPEN):
-            elections.append((e.eid, e.title, e.close_at, state))
+    for eid in eids:
+        election = steve.election.Election(db_fname, eid)
+        metadata = election.get_metadata()
+        elections.append((eid, metadata.title, metadata.close_at, 
metadata.state))
     
     # Sort by close_at descending (most recent first)
     elections.sort(key=lambda x: x[2] or 0, reverse=True)
diff --git a/v3/steve/election.py b/v3/steve/election.py
index d1feb87..dd7bd3a 100644
--- a/v3/steve/election.py
+++ b/v3/steve/election.py
@@ -502,6 +502,21 @@ class Election:
         )
         return [row for row in db.q_upcoming_to_me.fetchall()]
 
+    @classmethod
+    def list_closed_election_ids(cls, db_fname, include_open=False):
+        "Return a list of Election IDs for closed elections, optionally 
including open ones."
+        db = cls.open_database(db_fname)
+        
+        eids = []
+        db.q_closed_election_ids.perform()
+        eids.extend(row.eid for row in db.q_closed_election_ids.fetchall())
+        
+        if include_open:
+            db.q_open_election_ids.perform()
+            eids.extend(row.eid for row in db.q_open_election_ids.fetchall())
+        
+        return eids
+
     def set_open_at(self, timestamp):
         "Set the open_at timestamp for this Election."
         self.c_set_open_at.perform(timestamp, self.eid)

Reply via email to