Replace references to UTC_TIMESTAMP in SQL queries with a DateTimeFormat generated parameter

This commit is contained in:
Hypolite Petovan 2021-12-02 09:19:01 -05:00
parent ecaed2a845
commit 80da47921e
14 changed files with 37 additions and 28 deletions

View file

@ -2258,8 +2258,8 @@ class Item
$condition[] = $network;
}
$condition[0] .= " AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY";
$condition[] = $days;
$condition[0] .= " AND `received` < ?";
$condition[] = DateTimeFormat::utc('now - ' . $days . ' day');
$items = Post::select(['resource-id', 'starred', 'id', 'post-type', 'uid', 'uri-id'], $condition);

View file

@ -54,7 +54,7 @@ class PushSubscriber
{
// We'll push to each subscriber that has push > 0,
// i.e. there has been an update (set in notifier.php).
$subscribers = DBA::select('push_subscriber', ['id', 'push', 'callback_url', 'nickname'], ["`push` > 0 AND `next_try` < UTC_TIMESTAMP()"]);
$subscribers = DBA::select('push_subscriber', ['id', 'push', 'callback_url', 'nickname'], ["`push` > 0 AND `next_try` < ?", DateTimeFormat::utcNow()]);
while ($subscriber = DBA::fetch($subscribers)) {
// We always handle retries with low priority

View file

@ -29,6 +29,7 @@ use Friendica\Core\System;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
/**
@ -547,7 +548,7 @@ class Tag
{
// Get a uri-id that is at least X hours old.
// We use the uri-id in the query for the hash tags since this is much faster
$post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? HOUR", 0, $period],
$post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < ?", 0, DateTimeFormat::utc('now - ' . $period . ' hour')],
['order' => ['received' => true]]);
if (empty($post['uri-id'])) {
return [];
@ -600,7 +601,7 @@ class Tag
{
// Get a uri-id that is at least X hours old.
// We use the uri-id in the query for the hash tags since this is much faster
$post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? HOUR", 0, $period],
$post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < ?", 0, DateTimeFormat::utc('now - ' . $period . ' hour')],
['order' => ['received' => true]]);
if (empty($post['uri-id'])) {
return [];