liquid_feedback_core

diff lf_update_issue_order.c @ 398:806561cce3b1

New table "issue_order" for ordering fields to avoid a bottleneck with locking
author jbe
date Fri Oct 11 20:07:41 2013 +0200 (2013-10-11)
parents d93428e4edad
children db863178d98b
line diff
     1.1 --- a/lf_update_issue_order.c	Fri Oct 11 13:42:16 2013 +0200
     1.2 +++ b/lf_update_issue_order.c	Fri Oct 11 20:07:41 2013 +0200
     1.3 @@ -178,20 +178,20 @@
     1.4    PGresult *res;
     1.5    char *cmd;
     1.6    int i;
     1.7 -  if (asprintf(&cmd, "BEGIN; UPDATE \"issue\" SET \"order_in_admission_state\" = NULL WHERE \"area_id\" = %s AND (\"state\" = 'admission' OR \"order_in_admission_state\" NOTNULL)", escaped_area_id) < 0) {
     1.8 +  if (asprintf(&cmd, "BEGIN; DELETE FROM \"issue_order\" USING \"issue\" WHERE \"issue_order\".\"id\" = \"issue\".\"id\" AND \"issue\".\"area_id\" = %s", escaped_area_id) < 0) {
     1.9      fprintf(stderr, "Could not prepare query string in memory.\n");
    1.10      abort();
    1.11    }
    1.12    res = PQexec(db, cmd);
    1.13    free(cmd);
    1.14    if (!res) {
    1.15 -    fprintf(stderr, "Error in pqlib while sending SQL command to initiate issue update.\n");
    1.16 +    fprintf(stderr, "Error in pqlib while sending SQL command to initiate issue order update.\n");
    1.17      return 1;
    1.18    } else if (
    1.19      PQresultStatus(res) != PGRES_COMMAND_OK &&
    1.20      PQresultStatus(res) != PGRES_TUPLES_OK
    1.21    ) {
    1.22 -    fprintf(stderr, "Error while executing SQL command to initiate issue update:\n%s", PQresultErrorMessage(res));
    1.23 +    fprintf(stderr, "Error while executing SQL command to initiate issue order update:\n%s", PQresultErrorMessage(res));
    1.24      PQclear(res);
    1.25      return 1;
    1.26    } else {
    1.27 @@ -204,7 +204,7 @@
    1.28        fprintf(stderr, "Could not escape literal in memory.\n");
    1.29        abort();
    1.30      }
    1.31 -    if (asprintf(&cmd, "UPDATE \"issue\" SET \"order_in_admission_state\" = %i WHERE \"id\" = %s", candidates[i].seat, escaped_issue_id) < 0) {
    1.32 +    if (asprintf(&cmd, "INSERT INTO \"issue_order\" (\"id\", \"order_in_admission_state\") VALUES (%i, %s)", candidates[i].seat, escaped_issue_id) < 0) {
    1.33        fprintf(stderr, "Could not prepare query string in memory.\n");
    1.34        abort();
    1.35      }
    1.36 @@ -212,12 +212,12 @@
    1.37      res = PQexec(db, cmd);
    1.38      free(cmd);
    1.39      if (!res) {
    1.40 -      fprintf(stderr, "Error in pqlib while sending SQL command to update issue order.\n");
    1.41 +      fprintf(stderr, "Error in pqlib while sending SQL command to insert issue order.\n");
    1.42      } else if (
    1.43        PQresultStatus(res) != PGRES_COMMAND_OK &&
    1.44        PQresultStatus(res) != PGRES_TUPLES_OK
    1.45      ) {
    1.46 -      fprintf(stderr, "Error while executing SQL command to update issue order:\n%s", PQresultErrorMessage(res));
    1.47 +      fprintf(stderr, "Error while executing SQL command to insert issue order:\n%s", PQresultErrorMessage(res));
    1.48        PQclear(res);
    1.49      } else {
    1.50        PQclear(res);

Impressum / About Us