New founction to count threads
This commit is contained in:
parent
c972cce740
commit
178bc543e3
5 changed files with 44 additions and 20 deletions
|
@ -156,6 +156,27 @@ class Post
|
|||
return DBA::count('post-user-view', $condition, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the post-thread-user-view records satisfying the provided condition
|
||||
*
|
||||
* @param array $condition array of fields for condition
|
||||
* @param array $params Array of several parameters
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* Example:
|
||||
* $condition = ["uid" => 1, "network" => 'dspr'];
|
||||
* or:
|
||||
* $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr'];
|
||||
*
|
||||
* $count = Post::count($condition);
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function countThread(array $condition = [], array $params = [])
|
||||
{
|
||||
return DBA::count('post-thread-user-view', $condition, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the post-view records satisfying the provided condition
|
||||
*
|
||||
|
|
|
@ -294,7 +294,7 @@ class BaseApi extends BaseModule
|
|||
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60);
|
||||
|
||||
$condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom];
|
||||
$posts_day = Post::count($condition);
|
||||
$posts_day = Post::countThread($condition);
|
||||
|
||||
if ($posts_day > $throttle_day) {
|
||||
Logger::info('Daily posting limit reached', ['uid' => $uid, 'posts' => $posts_day, 'limit' => $throttle_day]);
|
||||
|
@ -310,7 +310,7 @@ class BaseApi extends BaseModule
|
|||
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7);
|
||||
|
||||
$condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom];
|
||||
$posts_week = Post::count($condition);
|
||||
$posts_week = Post::countThread($condition);
|
||||
|
||||
if ($posts_week > $throttle_week) {
|
||||
Logger::info('Weekly posting limit reached', ['uid' => $uid, 'posts' => $posts_week, 'limit' => $throttle_week]);
|
||||
|
@ -326,7 +326,7 @@ class BaseApi extends BaseModule
|
|||
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30);
|
||||
|
||||
$condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom];
|
||||
$posts_month = Post::count($condition);
|
||||
$posts_month = Post::countThread($condition);
|
||||
|
||||
if ($posts_month > $throttle_month) {
|
||||
Logger::info('Monthly posting limit reached', ['uid' => $uid, 'posts' => $posts_month, 'limit' => $throttle_month]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue