Merge pull request #9293 from annando/issue-9288
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Sun, 27 Sep 2020 12:26:52 +0000 (14:26 +0200)
committerGitHub <noreply@github.com>
Sun, 27 Sep 2020 12:26:52 +0000 (14:26 +0200)
Issue 9288: Endless scrolling on the community page

src/Model/Tag.php
src/Module/Settings/UserExport.php
src/Worker/UpdatePublicContacts.php
static/defaults.config.php

index 0d6c9cf..c4ff34c 100644 (file)
@@ -537,7 +537,7 @@ class Tag
         */
        public static function getLocalTrendingHashtags(int $period, $limit = 10)
        {
-               $tags = DI::cache()->get('local_trending_tags');
+               $tags = DI::cache()->get('local_trending_tags-' . $period . '-' . $limit);
                if (!empty($tags)) {
                        return $tags;
                } else {
@@ -563,7 +563,7 @@ class Tag
 
                if (DBA::isResult($tagsStmt)) {
                        $tags = DBA::toArray($tagsStmt);
-                       DI::cache()->set('local_trending_tags', $tags, Duration::HOUR);
+                       DI::cache()->set('local_trending_tags-' . $period . '-' . $limit, $tags, Duration::HOUR);
                        return $tags;
                }
 
index 1325053..25e305e 100644 (file)
@@ -27,6 +27,7 @@ use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use Friendica\DI;
+use Friendica\Model\Item;
 use Friendica\Module\BaseSettings;
 
 /**
@@ -115,10 +116,13 @@ class UserExport extends BaseSettings
                while ($row = DBA::fetch($rows)) {
                        $p = [];
                        foreach ($dbStructure[$table]['fields'] as $column => $field) {
+                               if (!isset($row[$column])) {
+                                       continue;
+                               }
                                if ($field['type'] == 'datetime') {
-                                       $p[$column] = $v ?? DBA::NULL_DATETIME;
+                                       $p[$column] = $row[$column] ?? DBA::NULL_DATETIME;
                                } else {
-                                       $p[$column] = $v;
+                                       $p[$column] = $row[$column];
                                }
                        }
                        $result[] = $p;
@@ -140,6 +144,9 @@ class UserExport extends BaseSettings
 
                        foreach ($r as $rr) {
                                foreach ($rr as $k => $v) {
+                                       if (empty($dbStructure[$table]['fields'][$k])) {
+                                               continue;
+                                       }
                                        switch ($dbStructure[$table]['fields'][$k]['type']) {
                                                case 'datetime':
                                                        $result[$k] = $v ?? DBA::NULL_DATETIME;
@@ -162,9 +169,9 @@ class UserExport extends BaseSettings
                // write the table header (like Mastodon)
                echo "Account address, Show boosts\n";
                // get all the contacts
-               $contacts = DBA::select('contact', ['addr'], ['uid' => $_SESSION['uid'], 'self' => false, 'rel' => [1,3], 'deleted' => false]);
+               $contacts = DBA::select('contact', ['addr', 'url'], ['uid' => $_SESSION['uid'], 'self' => false, 'rel' => [1,3], 'deleted' => false]);
                while ($contact = DBA::fetch($contacts)) {
-                       echo $contact['addr'] . ", true\n";
+                       echo ($contact['addr'] ? $contact['addr'] : $contact['url']) . ", true\n";
                }
                DBA::close($contacts);
        }
@@ -238,13 +245,8 @@ class UserExport extends BaseSettings
                // chunk the output to avoid exhausting memory
 
                for ($x = 0; $x < $total; $x += 500) {
-                       $r = q("SELECT * FROM `item` WHERE `uid` = %d LIMIT %d, %d",
-                               intval(local_user()),
-                               intval($x),
-                               intval(500)
-                       );
-
-                       $output = ['item' => $r];
+                       $items = Item::selectToArray(Item::ITEM_FIELDLIST, ['uid' => local_user()], ['limit' => [$x, 500]]);
+                       $output = ['item' => $items];
                        echo json_encode($output, JSON_PARTIAL_OUTPUT_ON_ERROR). "\n";
                }
        }
index 453606b..519478e 100644 (file)
@@ -25,6 +25,7 @@ use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Util\DateTimeFormat;
 
 /**
@@ -39,6 +40,12 @@ class UpdatePublicContacts
                $condition = ["`network` IN (?, ?, ?, ?) AND `uid` = ? AND NOT `self` AND `last-update` < ?",
                        Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, 0, $last_updated];
 
+               if (DI::config()->get('system', 'update_active_contacts')) {
+                       $condition = DBA::mergeConditions($condition, ["(`id` IN (SELECT `author-id` FROM `item`) OR
+                       `id` IN (SELECT `owner-id` FROM `item`) OR `id` IN (SELECT `causer-id` FROM `item`) OR
+                       `id` IN (SELECT `cid` FROM `post-tag`) OR `id` IN (SELECT `cid` FROM `user-contact`))"]);
+               }
+
                $oldest_date = '';
                $oldest_id = '';
                $contacts = DBA::select('contact', ['id', 'last-update'], $condition, ['limit' => 100, 'order' => ['last-update']]);
index fbd3787..11731f2 100644 (file)
@@ -475,6 +475,10 @@ return [
                // Maximum number of posts that a user can send per month with the API. 0 to disable monthly throttling.
                'throttle_limit_month' => 0,
 
+               // update_active_contacts (Boolean)
+               // When activated, only public contacts will be activated regularly that are used for example in items or tags.
+               'update_active_contacts' => false,
+
                // username_min_length (Integer)
                // The minimum character length a username can be.
                // This length is check once the username has been trimmed and multiple spaces have been collapsed into one.