Skip to content
Permalink
Browse files

updated getRecentReviews to include reviews in the A-file, even if th…

…ey fall outside what would otherwise be considered the 'recent' time horizon
  • Loading branch information...
RocketMan committed Jul 13, 2019
1 parent 19d3102 commit e0578f3aaf74216910850197798084ec475e7159
Showing with 78 additions and 10 deletions.
  1. +37 −0 db/convert_v2_2_0_to_v2_3_0.sql
  2. +1 −0 db/zkdbSchema.sql
  3. +40 −10 engine/impl/Review.php
@@ -0,0 +1,37 @@
/*
* Zookeeper Online
*
* @author Jim Mason <jmason@ibinx.com>
* @copyright Copyright (C) 1997-2019 Jim Mason <jmason@ibinx.com>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* version 3, along with this program. If not, see
* http://www.gnu.org/licenses/
*/

/**
* IMPORTANT NOTE:
*
* Run this script ONLY if you are converting an existing Zookeeper Online
* v2_2_0 database for use with the current codebase.
*
* If you are creating a new database, run zkdbSchema.sql and then populate
* the resulting db using the various bootstrap scripts as appropriate.
*/

--
-- Database: `zkdb`
--

ALTER TABLE reviews ADD INDEX created (created);
@@ -260,6 +260,7 @@ CREATE TABLE IF NOT EXISTS `reviews` (
PRIMARY KEY (`id`),
KEY `user` (`user`),
KEY `tag` (`tag`),
KEY `created` (`created`),
FULLTEXT KEY `review` (`review`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

@@ -39,9 +39,14 @@ public function getNumReviews($tag, $loggedIn = 0) {
$row = $this->executeAndFetch($stmt, \PDO::FETCH_BOTH);
return $row[0];
}
public function getRecentReviews($user = "", $weeks = 0, $limit = 0, $loggedIn = 0) {
private function getRecentSubquery($user = "", $weeks = 0, $loggedIn = 0) {
$query = "SELECT r.tag, a.airname, r.user, r.created FROM reviews r ";
if(!$weeks)
$query .= "LEFT JOIN currents c ON c.tag = r.tag AND " .
"c.adddate <= NOW() AND c.pulldate > NOW() ";
$query .= "LEFT JOIN airnames a ON r.airname = a.id ";
$op = "AND";
@@ -52,25 +57,50 @@ public function getRecentReviews($user = "", $weeks = 0, $limit = 0, $loggedIn =
$query .= "WHERE r.private=0 ";
else
$op = "WHERE";
if($weeks)
$query .= "$op r.created >= ? ";
else
$query .= "$op c.tag IS NOT NULL ";
return $query;
}
public function getRecentReviews($user = "", $weeks = 0, $limit = 0, $loggedIn = 0) {
if($weeks) {
$t = getdate(time());
$start = date("Y-m-d", mktime(0,0,0,
$t["mon"],
$t["mday"]- $weeks*7,
$t["year"]));
$query .= "$op r.created >= ? ";
// The UNION construct is obtuse but efficient, as it allows
// us to use multiple indexes on the reviews table, thus
// avoiding a table scan, which MySQL would do otherwise.
//
// See: https://www.techfounder.net/2008/10/15/optimizing-or-union-operations-in-mysql/
$query = "SELECT z.tag, z.airname, z.user, z.created FROM (";
$query .= $this->getRecentSubquery($user, $weeks, $loggedIn);
$query .= "UNION ";
$query .= $this->getRecentSubquery($user, 0, $loggedIn);
$query .= ") AS z GROUP BY z.tag ORDER BY z.created DESC";
} else {
$query = $this->getRecentSubquery($user, 0, $loggedIn);
$query .= "GROUP BY r.tag ORDER BY r.created DESC";
}
$query .= "GROUP BY r.tag ORDER BY r.created DESC";
if($limit)
$query .= " LIMIT ?";
$stmt = $this->prepare($query);
$p = 1;
if($user)
$stmt->bindValue($p++, $user);
if($weeks)
if($weeks) {
$t = getdate(time());
$start = date("Y-m-d", mktime(0,0,0,
$t["mon"],
$t["mday"]- $weeks*7,
$t["year"]));
$stmt->bindValue($p++, $start);
if($user)
$stmt->bindValue($p++, $user);
}
if($limit)
$stmt->bindValue($p++, (int)$limit, \PDO::PARAM_INT);
return $this->execute($stmt, \PDO::FETCH_BOTH);

0 comments on commit e0578f3

Please sign in to comment.
You can’t perform that action at this time.