[DATABASE] Always quote identifiers
The code used to operate under the assumption that MariaDB doesn't support quoting identifiers. Not only is that not exactly true, but MariaDB has reserved keywords that cannot be used as table or column names unquoted.
This commit is contained in:
@@ -326,15 +326,18 @@ class Nodeinfo_2_0Action extends Action
|
||||
*/
|
||||
public function getActiveUsers(int $days): int
|
||||
{
|
||||
$userTable = common_database_tablename('user');
|
||||
$query = "
|
||||
SELECT COUNT(DISTINCT profile_id) as active_users_count
|
||||
SELECT COUNT(DISTINCT profile_id) AS active_users_count
|
||||
FROM (
|
||||
SELECT profile_id FROM notice WHERE notice.created >= NOW() - INTERVAL {$days} DAY AND notice.is_local = 1
|
||||
SELECT profile_id FROM notice
|
||||
WHERE notice.created >= (CURRENT_TIMESTAMP - INTERVAL {$days} DAY) AND notice.is_local = 1
|
||||
UNION ALL
|
||||
SELECT user_id FROM fave INNER JOIN user ON fave.user_id = user.id WHERE fave.created >= NOW() - INTERVAL {$days} DAY
|
||||
SELECT user_id FROM fave INNER JOIN {$userTable} ON fave.user_id = {$userTable}.id
|
||||
WHERE fave.created >= (CURRENT_TIMESTAMP - INTERVAL {$days} DAY)
|
||||
UNION ALL
|
||||
SELECT id FROM user WHERE user.created >= NOW() - INTERVAL {$days} DAY
|
||||
) as source";
|
||||
SELECT id FROM {$userTable} WHERE {$userTable}.created >= (CURRENT_TIMESTAMP - INTERVAL {$days} DAY)
|
||||
) AS source";
|
||||
|
||||
$activeUsersCount = new DB_DataObject();
|
||||
$activeUsersCount->query($query);
|
||||
|
Reference in New Issue
Block a user