]> git.mxchange.org Git - friendica.git/commitdiff
New founction to count threads
authorMichael <heluecht@pirati.ca>
Thu, 8 Jul 2021 17:32:41 +0000 (17:32 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 8 Jul 2021 17:32:41 +0000 (17:32 +0000)
database.sql
doc/database/db_post-thread-user.md
src/Model/Post.php
src/Module/BaseApi.php
static/dbstructure.config.php

index 69ae84696e79fc0726d00ed19e3075bd8094dc92..160d59aae1d919712f02f1f78938471b14653d9f 100644 (file)
@@ -1294,6 +1294,7 @@ CREATE TABLE IF NOT EXISTS `post-thread-user` (
         INDEX `post-user-id` (`post-user-id`),
         INDEX `commented` (`commented`),
         INDEX `uid_received` (`uid`,`received`),
         INDEX `post-user-id` (`post-user-id`),
         INDEX `commented` (`commented`),
         INDEX `uid_received` (`uid`,`received`),
+        INDEX `uid_wall_received` (`uid`,`wall`,`received`),
         INDEX `uid_pinned` (`uid`,`pinned`),
         INDEX `uid_commented` (`uid`,`commented`),
         INDEX `uid_starred` (`uid`,`starred`),
         INDEX `uid_pinned` (`uid`,`pinned`),
         INDEX `uid_commented` (`uid`,`commented`),
         INDEX `uid_starred` (`uid`,`starred`),
index 3efb5a77af42aa4bd16607981c07a199bec84e2f..7307dc78d67b4d73c810441d82c547d2a97c30ce 100644 (file)
@@ -35,23 +35,24 @@ Fields
 Indexes
 ------------
 
 Indexes
 ------------
 
-| Name          | Fields         |
-| ------------- | -------------- |
-| PRIMARY       | uid, uri-id    |
-| uri-id        | uri-id         |
-| owner-id      | owner-id       |
-| author-id     | author-id      |
-| causer-id     | causer-id      |
-| uid           | uid            |
-| contact-id    | contact-id     |
-| psid          | psid           |
-| post-user-id  | post-user-id   |
-| commented     | commented      |
-| uid_received  | uid, received  |
-| uid_pinned    | uid, pinned    |
-| uid_commented | uid, commented |
-| uid_starred   | uid, starred   |
-| uid_mention   | uid, mention   |
+| Name              | Fields              |
+| ----------------- | ------------------- |
+| PRIMARY           | uid, uri-id         |
+| uri-id            | uri-id              |
+| owner-id          | owner-id            |
+| author-id         | author-id           |
+| causer-id         | causer-id           |
+| uid               | uid                 |
+| contact-id        | contact-id          |
+| psid              | psid                |
+| post-user-id      | post-user-id        |
+| commented         | commented           |
+| uid_received      | uid, received       |
+| uid_wall_received | uid, wall, received |
+| uid_pinned        | uid, pinned         |
+| uid_commented     | uid, commented      |
+| uid_starred       | uid, starred        |
+| uid_mention       | uid, mention        |
 
 Foreign Keys
 ------------
 
 Foreign Keys
 ------------
index 902525f9922415b738ef85ae3bfdffbdc1dc45f1..7b77276de83c38528a410958174d5f2a6da6915a 100644 (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
         *
index d2aa9662c184118f615c365c4cf82b22b27dd752..9d5c36f42360b477f8e87342bfa71fb3d96a1581 100644 (file)
@@ -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];
                        $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]);
 
                        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];
                        $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]);
 
                        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];
                        $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]);
 
                        if ($posts_month > $throttle_month) {
                                Logger::info('Monthly posting limit reached', ['uid' => $uid, 'posts' => $posts_month, 'limit' => $throttle_month]);
index f302f1ecc40699b1e65be6be5dbe2f82f8be31b0..7821774e75712b9e35afe0d9df47bedde9594db3 100644 (file)
@@ -1326,6 +1326,7 @@ return [
                        "post-user-id" => ["post-user-id"],
                        "commented" => ["commented"],
                        "uid_received" => ["uid", "received"],
                        "post-user-id" => ["post-user-id"],
                        "commented" => ["commented"],
                        "uid_received" => ["uid", "received"],
+                       "uid_wall_received" => ["uid", "wall", "received"],
                        "uid_pinned" => ["uid", "pinned"],
                        "uid_commented" => ["uid", "commented"],
                        "uid_starred" => ["uid", "starred"],
                        "uid_pinned" => ["uid", "pinned"],
                        "uid_commented" => ["uid", "commented"],
                        "uid_starred" => ["uid", "starred"],