liquid_feedback_core
diff lf_update.c @ 1:23092eb00e16
Version beta2
Serious bugfix in SQL function create_snapshot(...), which caused wrong counting of opinions on suggestions
lf_update now deletes expired sessions
Redundancy in SQL function check_everything() removed by using existent views
Serious bugfix in SQL function create_snapshot(...), which caused wrong counting of opinions on suggestions
lf_update now deletes expired sessions
Redundancy in SQL function check_everything() removed by using existent views
author | jbe |
---|---|
date | Tue Nov 03 12:00:00 2009 +0100 (2009-11-03) |
parents | 8d021cb5eaf4 |
children | 6133c0a62378 |
line diff
1.1 --- a/lf_update.c Tue Oct 27 12:00:00 2009 +0100 1.2 +++ b/lf_update.c Tue Nov 03 12:00:00 2009 +0100 1.3 @@ -4,11 +4,15 @@ 1.4 #include <libpq-fe.h> 1.5 1.6 int main(int argc, char **argv) { 1.7 + 1.8 + // variable declarations: 1.9 int i, count; 1.10 char *conninfo; 1.11 PGconn *db; 1.12 PGresult *list; 1.13 PGresult *status; 1.14 + 1.15 + // parse command line: 1.16 if (argc == 0) return 1; 1.17 if (argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { 1.18 FILE *out; 1.19 @@ -37,6 +41,8 @@ 1.20 strcat(conninfo, argv[i]); 1.21 } 1.22 } 1.23 + 1.24 + // connect to database: 1.25 db = PQconnectdb(conninfo); 1.26 if (!db) { 1.27 fprintf(stderr, "Error: Could not create database handle\n"); 1.28 @@ -46,6 +52,22 @@ 1.29 fprintf(stderr, "Could not open connection:\n%s", PQerrorMessage(db)); 1.30 return 1; 1.31 } 1.32 + 1.33 + // delete expired sessions: 1.34 + status = PQexec(db, "DELETE FROM \"expired_session\""); 1.35 + if (!status) { 1.36 + fprintf(stderr, "Error in pqlib while sending SQL command deleting expired sessions\n"); 1.37 + return 1; 1.38 + } 1.39 + if ( 1.40 + PQresultStatus(status) != PGRES_COMMAND_OK && 1.41 + PQresultStatus(status) != PGRES_TUPLES_OK 1.42 + ) { 1.43 + fprintf(stderr, "Error while executing SQL command deleting expired sessions:\n%s", PQresultErrorMessage(status)); 1.44 + return 1; 1.45 + } 1.46 + 1.47 + // update open issues: 1.48 list = PQexec(db, "SELECT \"id\" FROM \"open_issue\""); 1.49 if (!list) { 1.50 fprintf(stderr, "Error in pqlib while sending SQL command selecting open issues\n"); 1.51 @@ -62,6 +84,10 @@ 1.52 status = PQexecParams( 1.53 db, "SELECT \"check_issue\"($1)", 1, NULL, params, NULL, NULL, 0 1.54 ); 1.55 + if (!status) { 1.56 + fprintf(stderr, "Error in pqlib while sending SQL command to call function \"check_issue\"(...):\n"); 1.57 + return 1; 1.58 + } 1.59 if ( 1.60 PQresultStatus(status) != PGRES_COMMAND_OK && 1.61 PQresultStatus(status) != PGRES_TUPLES_OK 1.62 @@ -72,6 +98,9 @@ 1.63 PQclear(status); 1.64 } 1.65 PQclear(list); 1.66 + 1.67 + // calculate ranks after voting is finished: 1.68 + // (NOTE: This is a seperate process to avoid long transactions with locking) 1.69 list = PQexec(db, "SELECT \"id\" FROM \"issue_with_ranks_missing\""); 1.70 if (!list) { 1.71 fprintf(stderr, "Error in pqlib while sending SQL command selecting issues where ranks are missing\n"); 1.72 @@ -88,6 +117,10 @@ 1.73 status = PQexecParams( 1.74 db, "SELECT \"calculate_ranks\"($1)", 1, NULL, params, NULL, NULL, 0 1.75 ); 1.76 + if (!status) { 1.77 + fprintf(stderr, "Error in pqlib while sending SQL command to call function \"calculate_ranks\"(...):\n"); 1.78 + return 1; 1.79 + } 1.80 if ( 1.81 PQresultStatus(status) != PGRES_COMMAND_OK && 1.82 PQresultStatus(status) != PGRES_TUPLES_OK 1.83 @@ -98,6 +131,9 @@ 1.84 PQclear(status); 1.85 } 1.86 PQclear(list); 1.87 + 1.88 + // cleanup and exit 1.89 PQfinish(db); 1.90 return 0; 1.91 + 1.92 }