rssutils: start PDO switch
This commit is contained in:
parent
1d92297a96
commit
afcb105f4e
1 changed files with 46 additions and 38 deletions
|
@ -18,31 +18,38 @@ class RSSUtils {
|
|||
|
||||
static function update_feedbrowser_cache() {
|
||||
|
||||
$result = db_query("SELECT feed_url, site_url, title, COUNT(id) AS subscribers
|
||||
$pdo = Db::pdo();
|
||||
|
||||
$sth = $pdo->query("SELECT feed_url, site_url, title, COUNT(id) AS subscribers
|
||||
FROM ttrss_feeds WHERE feed_url NOT IN (SELECT feed_url FROM ttrss_feeds
|
||||
WHERE private IS true OR auth_login != '' OR auth_pass != '' OR feed_url LIKE '%:%@%/%')
|
||||
GROUP BY feed_url, site_url, title ORDER BY subscribers DESC LIMIT 1000");
|
||||
|
||||
db_query("BEGIN");
|
||||
$pdo->beginTransaction();
|
||||
|
||||
db_query("DELETE FROM ttrss_feedbrowser_cache");
|
||||
$pdo->query("DELETE FROM ttrss_feedbrowser_cache");
|
||||
|
||||
$count = 0;
|
||||
|
||||
while ($line = db_fetch_assoc($result)) {
|
||||
while ($line = $sth->fetch()) {
|
||||
|
||||
$subscribers = db_escape_string($line["subscribers"]);
|
||||
$feed_url = db_escape_string($line["feed_url"]);
|
||||
$title = db_escape_string($line["title"]);
|
||||
$site_url = db_escape_string($line["site_url"]);
|
||||
|
||||
$tmp_result = db_query("SELECT subscribers FROM
|
||||
ttrss_feedbrowser_cache WHERE feed_url = '$feed_url'");
|
||||
$tmph = $pdo->prepare("SELECT subscribers FROM
|
||||
ttrss_feedbrowser_cache WHERE feed_url = ?");
|
||||
$tmph->execute([$feed_url]);
|
||||
|
||||
if (db_num_rows($tmp_result) == 0) {
|
||||
if (!$tmph->fetch()) {
|
||||
|
||||
db_query("INSERT INTO ttrss_feedbrowser_cache
|
||||
(feed_url, site_url, title, subscribers) VALUES ('$feed_url',
|
||||
'$site_url', '$title', '$subscribers')");
|
||||
$tmph = $pdo->prepare("INSERT INTO ttrss_feedbrowser_cache
|
||||
(feed_url, site_url, title, subscribers)
|
||||
VALUES
|
||||
(?, ?, ?, ?)");
|
||||
|
||||
$tmph->execute([$feed_url, $site_url, $title, $subscribers]);
|
||||
|
||||
++$count;
|
||||
|
||||
|
@ -50,7 +57,7 @@ class RSSUtils {
|
|||
|
||||
}
|
||||
|
||||
db_query("COMMIT");
|
||||
$pdo->commit();
|
||||
|
||||
return $count;
|
||||
|
||||
|
@ -63,6 +70,8 @@ class RSSUtils {
|
|||
die("Schema version is wrong, please upgrade the database.\n");
|
||||
}
|
||||
|
||||
$pdo = Db::pdo();
|
||||
|
||||
if (!SINGLE_USER_MODE && DAEMON_UPDATE_LOGIN_LIMIT > 0) {
|
||||
if (DB_TYPE == "pgsql") {
|
||||
$login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".DAEMON_UPDATE_LOGIN_LIMIT." days'";
|
||||
|
@ -124,22 +133,23 @@ class RSSUtils {
|
|||
$updstart_thresh_qpart
|
||||
$query_order $query_limit";
|
||||
|
||||
$result = db_query($query);
|
||||
|
||||
if ($debug) _debug(sprintf("Scheduled %d feeds to update...", db_num_rows($result)));
|
||||
$res = $pdo->query($query);
|
||||
|
||||
$feeds_to_update = array();
|
||||
while ($line = db_fetch_assoc($result)) {
|
||||
while ($line = $res->fetch()) {
|
||||
array_push($feeds_to_update, $line['feed_url']);
|
||||
}
|
||||
|
||||
if ($debug) _debug(sprintf("Scheduled %d feeds to update...", count($feeds_to_update)));
|
||||
|
||||
// Update last_update_started before actually starting the batch
|
||||
// in order to minimize collision risk for parallel daemon tasks
|
||||
if (count($feeds_to_update) > 0) {
|
||||
$feeds_quoted = array_map(function ($s) { return "'" . db_escape_string($s) . "'"; }, $feeds_to_update);
|
||||
$feeds_qmarks = arr_qmarks($feeds_to_update);
|
||||
|
||||
db_query(sprintf("UPDATE ttrss_feeds SET last_update_started = NOW()
|
||||
WHERE feed_url IN (%s)", implode(',', $feeds_quoted)));
|
||||
$tmph = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW()
|
||||
WHERE feed_url IN ($feeds_qmarks)");
|
||||
$tmph->execute($feeds_to_update);
|
||||
}
|
||||
|
||||
$nf = 0;
|
||||
|
@ -147,25 +157,25 @@ class RSSUtils {
|
|||
|
||||
$batch_owners = array();
|
||||
|
||||
foreach ($feeds_to_update as $feed) {
|
||||
if($debug) _debug("Base feed: $feed");
|
||||
|
||||
//update_rss_feed($line["id"], true);
|
||||
|
||||
// since we have the data cached, we can deal with other feeds with the same url
|
||||
$tmp_result = db_query("SELECT DISTINCT ttrss_feeds.id,last_updated,ttrss_feeds.owner_uid
|
||||
$usth = $pdo->prepare("SELECT DISTINCT ttrss_feeds.id,last_updated,ttrss_feeds.owner_uid
|
||||
FROM ttrss_feeds, ttrss_users, ttrss_user_prefs WHERE
|
||||
ttrss_user_prefs.owner_uid = ttrss_feeds.owner_uid AND
|
||||
ttrss_users.id = ttrss_user_prefs.owner_uid AND
|
||||
ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL' AND
|
||||
ttrss_user_prefs.profile IS NULL AND
|
||||
feed_url = '".db_escape_string($feed)."'
|
||||
feed_url = ?
|
||||
$update_limit_qpart
|
||||
$login_thresh_qpart
|
||||
ORDER BY ttrss_feeds.id $query_limit");
|
||||
|
||||
if (db_num_rows($tmp_result) > 0) {
|
||||
while ($tline = db_fetch_assoc($tmp_result)) {
|
||||
foreach ($feeds_to_update as $feed) {
|
||||
if($debug) _debug("Base feed: $feed");
|
||||
|
||||
$usth->execute([$feed]);
|
||||
//update_rss_feed($line["id"], true);
|
||||
|
||||
if ($tline = $usth->fetch()) {
|
||||
if ($debug) _debug(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]);
|
||||
|
||||
if (array_search($tline["owner_uid"], $batch_owners) === FALSE)
|
||||
|
@ -180,7 +190,6 @@ class RSSUtils {
|
|||
++$nf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($nf > 0) {
|
||||
_debug(sprintf("Processed %d feeds in %.4f (sec), %.4f (sec/feed avg)", $nf,
|
||||
|
@ -197,7 +206,6 @@ class RSSUtils {
|
|||
Digest::send_headlines_digests($debug);
|
||||
|
||||
return $nf;
|
||||
|
||||
}
|
||||
|
||||
// this is used when subscribing
|
||||
|
|
Loading…
Reference in a new issue