New founction to count threads

This commit is contained in:
Michael 2021-07-08 17:32:41 +00:00
parent c972cce740
commit 178bc543e3
5 changed files with 44 additions and 20 deletions

View File

@ -1294,6 +1294,7 @@ CREATE TABLE IF NOT EXISTS `post-thread-user` (
INDEX `post-user-id` (`post-user-id`), INDEX `post-user-id` (`post-user-id`),
INDEX `commented` (`commented`), INDEX `commented` (`commented`),
INDEX `uid_received` (`uid`,`received`), INDEX `uid_received` (`uid`,`received`),
INDEX `uid_wall_received` (`uid`,`wall`,`received`),
INDEX `uid_pinned` (`uid`,`pinned`), INDEX `uid_pinned` (`uid`,`pinned`),
INDEX `uid_commented` (`uid`,`commented`), INDEX `uid_commented` (`uid`,`commented`),
INDEX `uid_starred` (`uid`,`starred`), INDEX `uid_starred` (`uid`,`starred`),

View File

@ -35,23 +35,24 @@ Fields
Indexes Indexes
------------ ------------
| Name | Fields | | Name | Fields |
| ------------- | -------------- | | ----------------- | ------------------- |
| PRIMARY | uid, uri-id | | PRIMARY | uid, uri-id |
| uri-id | uri-id | | uri-id | uri-id |
| owner-id | owner-id | | owner-id | owner-id |
| author-id | author-id | | author-id | author-id |
| causer-id | causer-id | | causer-id | causer-id |
| uid | uid | | uid | uid |
| contact-id | contact-id | | contact-id | contact-id |
| psid | psid | | psid | psid |
| post-user-id | post-user-id | | post-user-id | post-user-id |
| commented | commented | | commented | commented |
| uid_received | uid, received | | uid_received | uid, received |
| uid_pinned | uid, pinned | | uid_wall_received | uid, wall, received |
| uid_commented | uid, commented | | uid_pinned | uid, pinned |
| uid_starred | uid, starred | | uid_commented | uid, commented |
| uid_mention | uid, mention | | uid_starred | uid, starred |
| uid_mention | uid, mention |
Foreign Keys Foreign Keys
------------ ------------

View File

@ -156,6 +156,27 @@ class Post
return DBA::count('post-user-view', $condition, $params); 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 * Counts the post-view records satisfying the provided condition
* *

View File

@ -294,7 +294,7 @@ class BaseApi extends BaseModule
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60); $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60);
$condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom]; $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) { if ($posts_day > $throttle_day) {
Logger::info('Daily posting limit reached', ['uid' => $uid, 'posts' => $posts_day, 'limit' => $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); $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7);
$condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom]; $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) { if ($posts_week > $throttle_week) {
Logger::info('Weekly posting limit reached', ['uid' => $uid, 'posts' => $posts_week, 'limit' => $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); $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30);
$condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom]; $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) { if ($posts_month > $throttle_month) {
Logger::info('Monthly posting limit reached', ['uid' => $uid, 'posts' => $posts_month, 'limit' => $throttle_month]); Logger::info('Monthly posting limit reached', ['uid' => $uid, 'posts' => $posts_month, 'limit' => $throttle_month]);

View File

@ -1326,6 +1326,7 @@ return [
"post-user-id" => ["post-user-id"], "post-user-id" => ["post-user-id"],
"commented" => ["commented"], "commented" => ["commented"],
"uid_received" => ["uid", "received"], "uid_received" => ["uid", "received"],
"uid_wall_received" => ["uid", "wall", "received"],
"uid_pinned" => ["uid", "pinned"], "uid_pinned" => ["uid", "pinned"],
"uid_commented" => ["uid", "commented"], "uid_commented" => ["uid", "commented"],
"uid_starred" => ["uid", "starred"], "uid_starred" => ["uid", "starred"],