summaryrefslogtreecommitdiff
path: root/cgi-bin
diff options
context:
space:
mode:
authorMichael Sweet <michael.r.sweet@gmail.com>2016-05-25 17:33:36 -0400
committerMichael Sweet <michael.r.sweet@gmail.com>2016-05-25 17:33:36 -0400
commit9e6d7a0f879c7fb58209be4ba242b6131693964a (patch)
tree3eb3d35794ae40b9f3a7233ef749e89cf84ac2cb /cgi-bin
parentdffa3c7438d26a8a96c7f4937d85a1467b833e8e (diff)
downloadcups-9e6d7a0f879c7fb58209be4ba242b6131693964a.tar.gz
Improve performance of web interface with large numbers of jobs (Issue #3819)
Also re-work web interface to not allow the order to be changed (since that will negatively impact performance) but instead add first/last buttons to the pager.
Diffstat (limited to 'cgi-bin')
-rw-r--r--cgi-bin/classes.c34
-rw-r--r--cgi-bin/ipp-var.c63
-rw-r--r--cgi-bin/printers.c34
3 files changed, 48 insertions, 83 deletions
diff --git a/cgi-bin/classes.c b/cgi-bin/classes.c
index 7c4ac9d25..ae76a0c9f 100644
--- a/cgi-bin/classes.c
+++ b/cgi-bin/classes.c
@@ -1,7 +1,7 @@
/*
* Class status CGI for CUPS.
*
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
@@ -297,8 +297,7 @@ show_all_classes(http_t *http, /* I - Connection to server */
*response; /* IPP response */
cups_array_t *classes; /* Array of class objects */
ipp_attribute_t *pclass; /* Class object */
- int ascending, /* Order of classes (0 = descending) */
- first, /* First class to show */
+ int first, /* First class to show */
count; /* Number of classes */
const char *var; /* Form variable */
void *search; /* Search data */
@@ -370,25 +369,10 @@ show_all_classes(http_t *http, /* I - Connection to server */
sprintf(val, "%d", count);
cgiSetVariable("TOTAL", val);
- if ((var = cgiGetVariable("ORDER")) != NULL && *var)
- ascending = !_cups_strcasecmp(var, "asc");
- else
- ascending = 1;
-
- if (ascending)
- {
- for (i = 0, pclass = (ipp_attribute_t *)cupsArrayIndex(classes, first);
- i < CUPS_PAGE_MAX && pclass;
- i ++, pclass = (ipp_attribute_t *)cupsArrayNext(classes))
- cgiSetIPPObjectVars(pclass, NULL, i);
- }
- else
- {
- for (i = 0, pclass = (ipp_attribute_t *)cupsArrayIndex(classes, count - first - 1);
- i < CUPS_PAGE_MAX && pclass;
- i ++, pclass = (ipp_attribute_t *)cupsArrayPrev(classes))
- cgiSetIPPObjectVars(pclass, NULL, i);
- }
+ for (i = 0, pclass = (ipp_attribute_t *)cupsArrayIndex(classes, first);
+ i < CUPS_PAGE_MAX && pclass;
+ i ++, pclass = (ipp_attribute_t *)cupsArrayNext(classes))
+ cgiSetIPPObjectVars(pclass, NULL, i);
/*
* Save navigation URLs...
@@ -408,6 +392,12 @@ show_all_classes(http_t *http, /* I - Connection to server */
cgiSetVariable("NEXT", val);
}
+ if (count > CUPS_PAGE_MAX)
+ {
+ snprintf(val, sizeof(val), "%d", CUPS_PAGE_MAX * (count / CUPS_PAGE_MAX));
+ cgiSetVariable("LAST", val);
+ }
+
/*
* Then show everything...
*/
diff --git a/cgi-bin/ipp-var.c b/cgi-bin/ipp-var.c
index 827c55cfb..877d37c28 100644
--- a/cgi-bin/ipp-var.c
+++ b/cgi-bin/ipp-var.c
@@ -1,7 +1,7 @@
/*
* CGI <-> IPP variable routines for CUPS.
*
- * Copyright 2007-2015 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
@@ -1358,8 +1358,7 @@ cgiShowJobs(http_t *http, /* I - Connection to server */
*response; /* IPP response */
cups_array_t *jobs; /* Array of job objects */
ipp_attribute_t *job; /* Job object */
- int ascending, /* Order of jobs (0 = descending) */
- first, /* First job to show */
+ int first, /* First job to show */
count; /* Number of jobs */
const char *var, /* Form variable */
*query, /* Query string */
@@ -1395,6 +1394,17 @@ cgiShowJobs(http_t *http, /* I - Connection to server */
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "which-jobs",
NULL, which_jobs);
+ if ((var = cgiGetVariable("FIRST")) != NULL)
+ {
+ if ((first = atoi(var)) < 0)
+ first = 0;
+ }
+ else
+ first = 0;
+
+ if (first > 0)
+ ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "first-index", first + 1);
+
cgiGetAttributes(request, "jobs.tmpl");
/*
@@ -1417,7 +1427,7 @@ cgiShowJobs(http_t *http, /* I - Connection to server */
}
jobs = cgiGetIPPObjects(response, search);
- count = cupsArrayCount(jobs);
+ count = cupsArrayCount(jobs) + first;
if (search)
cgiFreeSearch(search);
@@ -1426,25 +1436,6 @@ cgiShowJobs(http_t *http, /* I - Connection to server */
* Figure out which jobs to display...
*/
- if ((var = cgiGetVariable("FIRST")) != NULL)
- first = atoi(var);
- else
- first = 0;
-
- if (first >= count)
- first = count - CUPS_PAGE_MAX;
-
- first = (first / CUPS_PAGE_MAX) * CUPS_PAGE_MAX;
-
- if (first < 0)
- first = 0;
-
- if ((var = cgiGetVariable("ORDER")) != NULL && *var)
- ascending = !_cups_strcasecmp(var, "asc");
- else
- ascending = !which_jobs || !*which_jobs ||
- !_cups_strcasecmp(which_jobs, "not-completed");
-
section = cgiGetVariable("SECTION");
cgiClearVariables();
@@ -1452,8 +1443,6 @@ cgiShowJobs(http_t *http, /* I - Connection to server */
if (query)
cgiSetVariable("QUERY", query);
- cgiSetVariable("ORDER", ascending ? "asc" : "dec");
-
cgiSetVariable("SECTION", section);
sprintf(val, "%d", count);
@@ -1462,20 +1451,10 @@ cgiShowJobs(http_t *http, /* I - Connection to server */
if (which_jobs)
cgiSetVariable("WHICH_JOBS", which_jobs);
- if (ascending)
- {
- for (i = 0, job = (ipp_attribute_t *)cupsArrayIndex(jobs, first);
- i < CUPS_PAGE_MAX && job;
- i ++, job = (ipp_attribute_t *)cupsArrayNext(jobs))
- cgiSetIPPObjectVars(job, NULL, i);
- }
- else
- {
- for (i = 0, job = (ipp_attribute_t *)cupsArrayIndex(jobs, count - first - 1);
- i < CUPS_PAGE_MAX && job;
- i ++, job = (ipp_attribute_t *)cupsArrayPrev(jobs))
- cgiSetIPPObjectVars(job, NULL, i);
- }
+ for (i = 0, job = (ipp_attribute_t *)cupsArrayFirst(jobs);
+ i < CUPS_PAGE_MAX && job;
+ i ++, job = (ipp_attribute_t *)cupsArrayNext(jobs))
+ cgiSetIPPObjectVars(job, NULL, i);
/*
* Save navigation URLs...
@@ -1504,6 +1483,12 @@ cgiShowJobs(http_t *http, /* I - Connection to server */
cgiSetVariable("NEXT", val);
}
+ if (count > CUPS_PAGE_MAX)
+ {
+ snprintf(val, sizeof(val), "%d", CUPS_PAGE_MAX * (count / CUPS_PAGE_MAX));
+ cgiSetVariable("LAST", val);
+ }
+
/*
* Then show everything...
*/
diff --git a/cgi-bin/printers.c b/cgi-bin/printers.c
index 7d2d5d6be..932c69995 100644
--- a/cgi-bin/printers.c
+++ b/cgi-bin/printers.c
@@ -1,7 +1,7 @@
/*
* Printer status CGI for CUPS.
*
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
@@ -304,8 +304,7 @@ show_all_printers(http_t *http, /* I - Connection to server */
*response; /* IPP response */
cups_array_t *printers; /* Array of printer objects */
ipp_attribute_t *printer; /* Printer object */
- int ascending, /* Order of printers (0 = descending) */
- first, /* First printer to show */
+ int first, /* First printer to show */
count; /* Number of printers */
const char *var; /* Form variable */
void *search; /* Search data */
@@ -387,25 +386,10 @@ show_all_printers(http_t *http, /* I - Connection to server */
sprintf(val, "%d", count);
cgiSetVariable("TOTAL", val);
- if ((var = cgiGetVariable("ORDER")) != NULL && *var)
- ascending = !_cups_strcasecmp(var, "asc");
- else
- ascending = 1;
-
- if (ascending)
- {
- for (i = 0, printer = (ipp_attribute_t *)cupsArrayIndex(printers, first);
- i < CUPS_PAGE_MAX && printer;
- i ++, printer = (ipp_attribute_t *)cupsArrayNext(printers))
- cgiSetIPPObjectVars(printer, NULL, i);
- }
- else
- {
- for (i = 0, printer = (ipp_attribute_t *)cupsArrayIndex(printers, count - first - 1);
- i < CUPS_PAGE_MAX && printer;
- i ++, printer = (ipp_attribute_t *)cupsArrayPrev(printers))
- cgiSetIPPObjectVars(printer, NULL, i);
- }
+ for (i = 0, printer = (ipp_attribute_t *)cupsArrayIndex(printers, first);
+ i < CUPS_PAGE_MAX && printer;
+ i ++, printer = (ipp_attribute_t *)cupsArrayNext(printers))
+ cgiSetIPPObjectVars(printer, NULL, i);
/*
* Save navigation URLs...
@@ -425,6 +409,12 @@ show_all_printers(http_t *http, /* I - Connection to server */
cgiSetVariable("NEXT", val);
}
+ if (count > CUPS_PAGE_MAX)
+ {
+ snprintf(val, sizeof(val), "%d", CUPS_PAGE_MAX * (count / CUPS_PAGE_MAX));
+ cgiSetVariable("LAST", val);
+ }
+
/*
* Then show everything...
*/