Skip to content

Commit 0ff6ef3

Browse files
authored
(goal): Suggested Feeds (#659)
* (wip): outline for hashtag flow * (feat): introduces cockroach db * [Sprint/Universe] [WIP] (goal): hashtags (#649) * (feat): autocomplete trending hashtags * (feat): index group hashtags * [Sprint/Xray] (goal): hashtags and suggested feeds (#660) * (feat): added User/Repository->getSuggestedHashtags (fix): fixed namespaces issue * (feat): iimplemented HashtagsProvider * (feat): implemented api/v2/hashtags/user * (feat): implemented api/v2/hashtags/suggested * (feat): api/v2/entities/suggested and moved getSuggestedHashtags to Feeds/Suggested/Repository * (feat): added flag to user entity for knowing if it has opted in to tags * (feat): implemented SQL queries and minor refactors to repositories * (fix): several fixes * (feat): added 'type' to suggested * (fix): cleanup * (feat): spec tests * (feat): ElasticSearch/Prepared/Update * (feat): persist tags * (feat): added cockroachdb provisioner * (fix): fixed suggested feed query * (fix): composer version update * (fix): drone * (fix): mapping spec tests * (fix): drone * (feat): added suggested for blogs * (feat): run types in parallel * (feat): trending saves into new suggested table * (fix): code cleanup * (feat): cleanup suggested table right before compiling the new one * (feat): populate entity_hashtags on trending compile * (fix): retrieve hashtag from url in api/v2/hashtags/user * (fix): user_hashtag remove query * (fix) Hashtag/User/Repository (#5) * (fix): fix repos and ensure sql injection not possible * (chore): add type to suggested repository to enable better querying * (fix): hashtags should be strings not arrays * (fix): opted in hashtags are not displaying first * (chore): remove categories from settings * (fix): sort by selected before sorting by score * (fix): spec tests * (chore): v2/hashtags/suggested should use Core/Hashtags/Suggested/Repository * (feat): ability to limit suggested hashtags query * (fix): drone * (fix): spec tests * (fix): type is in the suggested table vs entity_hashtags * (fix): drone * (fix): issues with top newsfeed * (fix): suggested hashtags should be in a time window * (feat): Trending hashtags from sidebar should stay in newsfeed and show the feed * (fix): spec tests * [Sprint/AdminatronONE] (feat) trending hashtags based on new categories (#669) * (feat) trending hashtags based on new categories * (chore) change table name to hidden_hashtags * [Sprint/Zodiac] (feat): suggested cli (#666) * (feat): new Suggested CLI * (feat): reset cli/trending as it was before, but with types in parallel * (fix): drone * (fix): drone * (fix): drone * (fix): Security/ACL spec tests * (fix): spec tests for Core\Trending\Repository * (fix): drone * (fix): drone * (fix): suggested feeds * (fix) my hashtags do not show unless they are trending (#673) * (feat): prefilled hashtags (#679) * [Sprint/Bojangles] (feat): introduce all in hashtags topbar (#680) * (feat): introduce #all at hashtags topbar * (fix): broken spec tests * (feat): spec tests * (fix): drone * (fix): drone * (fix): drone * (fix): return user hashtags alongside our own suggested * (feat): channels can tag themselves * (fix): remove lastSync time window * (fix): failing tests * (fix): suggested endpoint incorrect variable * (fix): adding tags to channel fix * (fix): bugs in manager feed for suggested * (chore): increase limit of test to match Manager
1 parent 8be4017 commit 0ff6ef3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2503
-232
lines changed

Controllers/Cli/Suggested.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
namespace Minds\Controllers\Cli;
3+
4+
use Minds\Core\Minds;
5+
use Minds\Cli;
6+
use Minds\Core\Feeds\Suggested\Manager;
7+
use Minds\Interfaces;
8+
9+
class Suggested extends Cli\Controller implements Interfaces\CliControllerInterface
10+
{
11+
/** @var Manager */
12+
private $manager;
13+
14+
public function __construct()
15+
{
16+
$minds = new Minds();
17+
$minds->start();
18+
$this->manager = new Manager();
19+
}
20+
21+
public function help($command = null)
22+
{
23+
$this->out('Syntax usage: cli trending <type>');
24+
}
25+
26+
public function exec()
27+
{
28+
$this->out('Syntax usage: cli trending <type>');
29+
}
30+
31+
public function sync_all()
32+
{
33+
error_reporting(E_ALL);
34+
ini_set('display_errors', 1);
35+
$this->out('Collecting trending items');
36+
37+
$this->manager->run('all');
38+
39+
$this->out('Completed syncing all');
40+
}
41+
42+
public function sync_newsfeed()
43+
{
44+
error_reporting(E_ALL);
45+
ini_set('display_errors', 1);
46+
$this->out('Syncing newsfeed');
47+
48+
$this->manager->run('newsfeed');
49+
50+
$this->out('Completed syncing newsfeed');
51+
}
52+
53+
public function sync_images()
54+
{
55+
$this->out('Syncing images');
56+
57+
$this->manager->run('images');
58+
59+
$this->out('Completed syncing images');
60+
}
61+
62+
public function sync_videos()
63+
{
64+
$this->out('Syncing videos');
65+
66+
$this->manager->run('videos');
67+
68+
$this->out('Completed syncing videos');
69+
}
70+
71+
public function sync_groups()
72+
{
73+
$this->out('Syncing groups');
74+
75+
$this->manager->run('groups');
76+
77+
$this->out('Completed syncing groups');
78+
}
79+
80+
public function sync_blogs()
81+
{
82+
$this->out('Syncing blogs');
83+
84+
$this->manager->run('blogs');
85+
86+
$this->out('Completed syncing blogs');
87+
}
88+
89+
}

Controllers/Cli/Trending.php

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
class Trending extends Cli\Controller implements Interfaces\CliControllerInterface
1515
{
1616
private static $limit = 72;
17-
1817
private $start;
1918
private $elasticsearch;
2019

@@ -28,64 +27,87 @@ public function exec()
2827
$this->out('Syntax usage: cli trending <type>');
2928
}
3029

31-
public function sync()
30+
public function sync_all()
3231
{
3332
error_reporting(E_ALL);
3433
ini_set('display_errors', 1);
3534
$this->out('Collecting trending items');
35+
$manager = new Core\Trending\Manager();
36+
$manager->run('all');
37+
$this->out('Completed syncing all');
38+
}
3639

40+
public function sync_newsfeed()
41+
{
42+
$this->out('Syncing newsfeed');
3743
$manager = new Core\Trending\Manager();
38-
$manager->run();
44+
$manager->run('newsfeed');
45+
$this->out('Completed syncing newsfeed');
46+
}
47+
48+
public function sync_images()
49+
{
50+
$this->out('Syncing images');
51+
$manager = new Core\Trending\Manager();
52+
$manager->run('images');
53+
$this->out('Completed syncing images');
54+
}
55+
56+
public function sync_videos()
57+
{
58+
$this->out('Syncing videos');
59+
$manager = new Core\Trending\Manager();
60+
$manager->run('videos');
61+
$this->out('Completed syncing videos');
62+
}
63+
64+
public function sync_groups()
65+
{
66+
$this->out('Syncing groups');
67+
$manager = new Core\Trending\Manager();
68+
$manager->run('groups');
69+
$this->out('Completed syncing groups');
70+
}
3971

40-
$this->out('Completed');
72+
public function sync_blogs()
73+
{
74+
$this->out('Syncing blogs');
75+
$manager = new Core\Trending\Manager();
76+
$manager->run('blogs');
77+
$this->out('Completed syncing blogs');
4178
}
4279

4380
public function legacy()
4481
{
4582
$hosts = Core\Di\Di::_()->get('Config')->elasticsearch['hosts'];
46-
4783
$this->elasticsearch = ClientBuilder::create()
4884
->setHosts($hosts)
4985
->build();
50-
51-
5286
$this->repository = Di::_()->get('Trending\Repository');
53-
5487
$span = $this->getOpt('span');
5588
$this->start = strtotime("-$span minutes");
5689
$end = new DateTime('now');
57-
5890
$this->groups();
59-
6091
$this->out("[complete] \n");
6192
}
6293

6394
private function groups()
6495
{
6596
$start = new DateTime('1 day ago');
6697
$end = new DateTime('now');
67-
6898
$pattern = '^\/groups\/profile\/([0-9]+)';
69-
7099
list($trendingUrls, $nextPage) = Di::_()->get('Trending\Services\GoogleAnalytics')
71100
->getByPageViews($pattern, $start, $end, '', (int) static::$limit * 1.5);
72-
73-
$guids = array_values(array_unique(array_map(function($item) use ($pattern) {
101+
$guids = array_values(array_unique(array_map(function ($item) use ($pattern) {
74102
preg_match("/$pattern/", $item['url'], $matches);
75-
76103
return $matches[1];
77104
}, $trendingUrls)));
78-
79105
$guids = array_slice($guids, 0, static::$limit);
80-
81106
$guids = array_values(array_filter($guids, function ($guid) {
82107
$entity = Entities\Factory::build($guid);
83108
return $entity && !Flags::isDeleted($entity);
84109
}));
85-
86110
Di::_()->get('Trending\Repository')->add('group', $guids);
87-
88111
$this->out("\nCollected " . count($guids) . ' groups');
89112
}
90-
91-
}
113+
}

Controllers/api/v1/admin/tagcloud.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function get($pages)
3030

3131
if ($hiddenRows) {
3232
foreach ($hiddenRows as $row) {
33-
$hidden[] = $row['column1'];
33+
$hidden[] = $row['hashtag'];
3434
}
3535
}
3636

Controllers/api/v1/blog.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ public function post($pages)
186186
$blog->setCategories($_POST['categories']);
187187
}
188188

189+
if (isset($_POST['tags'])) {
190+
$blog->setTags($_POST['tags']);
191+
}
192+
189193
if (isset($_POST['mature'])) {
190194
$blog->setMature(!!$_POST['mature']);
191195
}

Controllers/api/v1/channel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ public function post($pages)
210210
}
211211
}
212212

213+
214+
if (isset($_POST['tags']) && $_POST['tags']) {
215+
$update['tags'] = json_encode($_POST['tags']);
216+
$owner->$field = $update['tags'];
217+
}
218+
213219
/*try {
214220
$spam = new Core\Security\Spam();
215221
$spam->check($owner);

Controllers/api/v1/newsfeed.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ public function post($pages)
474474
$activity->setMature($_POST['mature']);
475475
}
476476

477+
if (isset($_POST['tags'])) {
478+
$activity->setTags($_POST['tags']);
479+
}
480+
477481
$user = Core\Session::getLoggedInUser();
478482
if ($user->isMature()) {
479483
$activity->setMature(true);
@@ -630,6 +634,10 @@ public function post($pages)
630634
}
631635
}
632636

637+
if (isset($_POST['tags'])) {
638+
$activity->setTags($_POST['tags']);
639+
}
640+
633641
try {
634642
$guid = $activity->save();
635643
} catch (\Exception $e) {

Controllers/api/v1/settings.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public function get($pages)
4242
$response['channel'] = $user->export();
4343
$response['channel']['email'] = $user->getEmail();
4444
$response['channel']['boost_rating'] = $user->getBoostRating();
45-
$response['channel']['categories'] = $user->getCategories();
4645
$response['channel']['disabled_emails'] = $user->disabled_emails;
4746

4847
$sessionsManager = Di::_()->get('Sessions\Manager');
@@ -141,39 +140,11 @@ public function post($pages)
141140
$user->setLanguage($_POST['language']);
142141
}
143142

144-
$allowedCategories = array_keys(Config::_()->get('categories'));
145-
$repository = Di::_()->get('Categories\Repository');
146-
$removedCategories = [];
147-
$newCategories = [];
148-
149-
if (isset($_POST['categories'])) {
150-
$categories = $_POST['categories'];
151-
foreach ($categories as $category) {
152-
if (in_array($category, $allowedCategories)) {
153-
$newCategories[] = $category;
154-
}
155-
}
156-
$removedCategories = array_diff($user->getCategories(), $newCategories);
157-
$user->setCategories($newCategories);
158-
}
159-
160143
$response = [];
161144
if (!$user->save()) {
162145
$response['status'] = 'error';
163146
}
164147

165-
// if the user was saved correctly, also update categories table
166-
if (isset($_POST['categories'])) {
167-
$repository->setFilter('opt-in')
168-
->setCategories($removedCategories)
169-
->setType('user')
170-
->remove($user->guid);
171-
172-
$repository->reset()
173-
->setCategories($newCategories)
174-
->add($user->guid);
175-
}
176-
177148
return Factory::response($response);
178149
}
179150

0 commit comments

Comments
 (0)