mirror of
https://github.com/friendica/friendica
synced 2025-04-23 19:10:13 +00:00
Issue 10935: Improved "GROUP BY" handling
This commit is contained in:
parent
4298afd479
commit
615c6ca696
4 changed files with 62 additions and 38 deletions
|
@ -55,7 +55,7 @@ class Create extends BaseApi
|
|||
$type = $this->getRequestValue($this->parameters, 'extension', 'json');
|
||||
|
||||
// input params
|
||||
$desc = $this->getRequestValue($request, 'desc') ?? '';
|
||||
$desc = $this->getRequestValue($request, 'desc', '');
|
||||
$album = $this->getRequestValue($request, 'album');
|
||||
$allow_cid = $this->getRequestValue($request, 'allow_cid');
|
||||
$deny_cid = $this->getRequestValue($request, 'deny_cid');
|
||||
|
|
|
@ -70,32 +70,35 @@ class Profile extends BaseModule
|
|||
|
||||
$last_updated = $last_updated_array[$last_updated_key] ?? 0;
|
||||
|
||||
$condition = ["`uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending`
|
||||
AND `visible` AND (NOT `deleted` OR `gravity` = ?)
|
||||
AND `wall` " . $sql_extra, $a->getProfileOwner(), GRAVITY_ACTIVITY];
|
||||
|
||||
if ($_GET['force'] && !empty($_GET['item'])) {
|
||||
// When the parent is provided, we only fetch this
|
||||
$sql_extra4 = " AND `parent` = " . intval($_GET['item']);
|
||||
$condition = DBA::mergeConditions($condition, ['parent' => $_GET['item']]);
|
||||
} elseif ($is_owner || !$last_updated) {
|
||||
// If the page user is the owner of the page we should query for unseen
|
||||
// items. Otherwise use a timestamp of the last succesful update request.
|
||||
$sql_extra4 = " AND `unseen`";
|
||||
$condition = DBA::mergeConditions($condition, ['unseen' => true]);
|
||||
} else {
|
||||
$gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);
|
||||
$sql_extra4 = " AND `received` > '" . $gmupdate . "'";
|
||||
$condition = DBA::mergeConditions($condition, ["`received` > ?", $gmupdate]);
|
||||
}
|
||||
|
||||
$items_stmt = DBA::p(
|
||||
"SELECT `parent-uri-id` AS `uri-id`, MAX(`created`), MAX(`received`) FROM `post-user-view`
|
||||
WHERE `uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending`
|
||||
AND `visible` AND (NOT `deleted` OR `gravity` = ?)
|
||||
AND `wall` $sql_extra4 $sql_extra
|
||||
GROUP BY `parent-uri-id` ORDER BY `received` DESC",
|
||||
$a->getProfileOwner(),
|
||||
GRAVITY_ACTIVITY
|
||||
);
|
||||
|
||||
if (!DBA::isResult($items_stmt)) {
|
||||
$items = Post::selectToArray(['parent-uri-id', 'created', 'received'], $condition, ['group_by' => ['parent-uri-id'], 'order' => ['received' => true]]);
|
||||
if (!DBA::isResult($items)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// @todo the DBA functions should handle "SELECT field AS alias" in the future,
|
||||
// so that this workaround here could be removed.
|
||||
$items = array_map(function ($item) {
|
||||
$item['uri-id'] = $item['parent-uri-id'];
|
||||
unset($item['parent-uri-id']);
|
||||
return $item;
|
||||
}, $items);
|
||||
|
||||
// Set a time stamp for this page. We will make use of it when we
|
||||
// search for new items (update routine)
|
||||
$last_updated_array[$last_updated_key] = time();
|
||||
|
@ -113,8 +116,6 @@ class Profile extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
$items = DBA::toArray($items_stmt);
|
||||
|
||||
$o .= DI::conversation()->create($items, 'profile', $a->getProfileOwner(), false, 'received', $a->getProfileOwner());
|
||||
|
||||
System::htmlUpdateExit($o);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue