summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Tänzer <neo@nhng.de>2013-01-22 23:20:04 +0100
committerMichael Tänzer <neo@nhng.de>2013-01-22 23:20:04 +0100
commitde583d9e02a9395c6508301f36a3fa021103818d (patch)
tree5631b9079ad9d67b745ed51d9f857aeee4eeece5
parent6dd2854e1d61800daa287f4f8139ade9c52a0a58 (diff)
downloadcacert-devel-bug-922.tar.gz
cacert-devel-bug-922.tar.xz
cacert-devel-bug-922.zip
bug 922: Optimise SQL queriesbug-922
Signed-off-by: Michael Tänzer <neo@nhng.de>
-rw-r--r--includes/account.php13
-rwxr-xr-xscripts/cron/warning.php43
2 files changed, 31 insertions, 25 deletions
diff --git a/includes/account.php b/includes/account.php
index 4f8ed03..f0e0243 100644
--- a/includes/account.php
+++ b/includes/account.php
@@ -622,13 +622,14 @@
echo $row['domain']."<br>\n";
$dres = mysql_query(
- "select distinct `domaincerts`.`id`
- from `domaincerts`, `domlink`
+ "select `domaincerts`.`id`
+ from `domaincerts`
where `domaincerts`.`domid` = '$id'
- or (
- `domaincerts`.`id` = `domlink`.`certid`
- and `domlink`.`domid` = '$id'
- )");
+ union distinct
+ select `domaincerts`.`id`
+ from `domaincerts`, `domlink`
+ where `domaincerts`.`id` = `domlink`.`certid`
+ and `domlink`.`domid` = '$id'");
while($drow = mysql_fetch_assoc($dres))
{
mysql_query(
diff --git a/scripts/cron/warning.php b/scripts/cron/warning.php
index 5cf7c31..0c97ba2 100755
--- a/scripts/cron/warning.php
+++ b/scripts/cron/warning.php
@@ -72,32 +72,37 @@ echo $row['fname']." ".$row['lname']." <".$row['email']."> (memid: ".$row['memid
foreach($days as $day => $warning)
{
- $query =
- "SELECT DISTINCT `domaincerts`.`id`,
+ $select_clause =
+ "`domaincerts`.`id`,
`users`.`fname`, `users`.`lname`, `users`.`email`,
`domains`.`memid`,
`domaincerts`.`subject`, `domaincerts`.`crt_name`,
`domaincerts`.`CN`,
`domaincerts`.`serial`,
- (UNIX_TIMESTAMP(`domaincerts`.`expire`) -
- UNIX_TIMESTAMP(NOW())) / 86400 AS `daysleft`
-
- FROM `users`, `domaincerts`, `domlink`, `domains`
- WHERE UNIX_TIMESTAMP(`domaincerts`.`expire`) -
+ (UNIX_TIMESTAMP(`domaincerts`.`expire`) -
+ UNIX_TIMESTAMP(NOW())) / 86400 AS `daysleft`";
+ $where_clause =
+ "UNIX_TIMESTAMP(`domaincerts`.`expire`) -
UNIX_TIMESTAMP(NOW()) > -7 * 86400
- AND UNIX_TIMESTAMP(`domaincerts`.`expire`) -
+ AND UNIX_TIMESTAMP(`domaincerts`.`expire`) -
UNIX_TIMESTAMP(NOW()) < $day * 86400
- AND `domaincerts`.`renewed` = 0
- AND `domaincerts`.`warning` <= '$warning'
- AND `domaincerts`.`revoked` = 0
- AND (
- `domaincerts`.`domid` = `domains`.`id`
- OR (
- `domaincerts`.`id` = `domlink`.`certid`
- AND `domlink`.`domid` = `domains`.`id`
- )
- )
- AND `domains`.`memid` = `users`.`id`";
+ AND `domaincerts`.`renewed` = 0
+ AND `domaincerts`.`warning` <= '$warning'
+ AND `domaincerts`.`revoked` = 0
+ AND `domains`.`memid` = `users`.`id`";
+ $query =
+ "SELECT $select_clause
+ FROM `users`, `domaincerts`, `domains`
+ WHERE $where_clause
+ AND `domaincerts`.`domid` = `domains`.`id`
+ UNION DISTINCT
+ SELECT $select_clause
+ FROM `users`,
+ `domaincerts` LEFT JOIN `domlink` ON
+ (`domaincerts`.`id` = `domlink`.`certid`),
+ `domains`
+ WHERE $where_clause
+ AND `domlink`.`domid` = `domains`.`id`";
$res = mysql_query($query);
while($row = mysql_fetch_assoc($res))
{