Selaa lähdekoodia

refactor (get-stats) use SQLite COUNT() instead of requesting all rows and counting within the program. fixes #11

George C. Privon 9 kuukautta sitten
vanhempi
commit
ff9160df89
2 muutettua tiedostoa jossa 10 lisäystä ja 9 poistoa
  1. 1 0
      CHANGELOG.md
  2. 9 9
      proposal_database.rkt

+ 1 - 0
CHANGELOG.md

@@ -10,6 +10,7 @@
 - combine creation and update scripts into a single file/tool
 - Modes are now specified as switches rather than as a free-form string. This change enables a more coherent/consistent method of parsing the arguments and getting program argument help (i.e., with `--help`)
 - Add `--list-open-calls` to show call information for unresolved (i.e., "submitted") proposals. This shows the number of proposals pending for each call, separated into PI'ed and Co-I'ed proposals.
+- Various internal refactoring for simplicity and off-loading of work to SQLite engine.
 
 ## v0.2.x
 

+ 9 - 9
proposal_database.rkt

@@ -338,17 +338,17 @@ resultdate TEXT DEFAULT '')")
                                        extrasel)))
   (values
    ; total number of proposals
-   (length (query-rows conn
-                       (string-append "SELECT ID FROM proposals"
-                                      mysel-one)))
+   (query-value conn
+                (string-append "SELECT COUNT(DISTINCT ID) FROM proposals"
+                               mysel-one))
    ; Number of pending proposals
-   (length (query-rows conn
-                       (string-append "SELECT ID FROM proposals WHERE status='submitted'"
-                                      mysel)))
+   (query-value conn
+                (string-append "SELECT COUNT(DISTINCT ID) FROM proposals WHERE status='submitted'"
+                               mysel))
    ; Number of rejected proposals
-   (length (query-rows conn
-                       (string-append "SELECT ID FROM proposals WHERE status LIKE '%rejected%'"
-                                      mysel)))))
+   (query-value conn
+                (string-append "SELECT COUNT(DISTINCT ID) FROM proposals WHERE status LIKE '%rejected%'"
+                               mysel))))
 
 ; make sure we can use the sqlite3 connection
 (define checkdblib