New item functions, improved feed cache behaviour

This commit is contained in:
Michael 2018-06-19 05:39:56 +00:00
parent 4714cb746b
commit ebd76285d8
2 changed files with 75 additions and 23 deletions

View File

@ -164,21 +164,63 @@ class Item extends BaseObject
return dba::p($sql, $condition);
}
/**
* @brief Select rows from the starting post in the item table
*
* @param integer $uid User ID
* @param array $fields Array of selected fields, empty for all
* @param array $condition Array of fields for condition
* @param array $params Array of several parameters
*
* @return boolean|object
*/
public static function selectThreadForUser($uid, array $selected = [], array $condition = [], $params = [])
{
$params['uid'] = $uid;
if (empty($selected)) {
$selected = Item::DISPLAY_FIELDLIST;
}
return self::selectThread($selected, $condition, $params);
}
/**
* Retrieve a single record from the starting post in the item table and returns it in an associative array
*
* @brief Retrieve a single record from a table
* @param integer $uid User ID
* @param array $selected
* @param array $condition
* @param array $params
* @return bool|array
* @see dba::select
*/
public static function selectFirstThreadForUser($uid, array $selected = [], array $condition = [], $params = [])
{
$params['uid'] = $uid;
if (empty($selected)) {
$selected = Item::DISPLAY_FIELDLIST;
}
return self::selectFirstThread($selected, $condition, $params);
}
/**
* Retrieve a single record from the starting post in the item table and returns it in an associative array
*
* @brief Retrieve a single record from a table
* @param array $fields
* @param array $condition
* @param array $params
* @return bool|array
* @see dba::select
*/
public static function selectFirstThreadForUser($uid, array $fields = [], array $condition = [], $params = [])
public static function selectFirstThread(array $fields = [], array $condition = [], $params = [])
{
$params['limit'] = 1;
$result = self::selectThreadForUser($uid, $fields, $condition, $params);
$result = self::selectThread($fields, $condition, $params);
if (is_bool($result)) {
return $result;
@ -192,17 +234,20 @@ class Item extends BaseObject
/**
* @brief Select rows from the starting post in the item table
*
* @param integer $uid User ID
* @param array $fields Array of selected fields, empty for all
* @param array $selected Array of selected fields, empty for all
* @param array $condition Array of fields for condition
* @param array $params Array of several parameters
*
* @return boolean|object
*/
public static function selectThreadForUser($uid, array $selected = [], array $condition = [], $params = [])
public static function selectThread(array $selected = [], array $condition = [], $params = [])
{
if (empty($selected)) {
$selected = Item::DISPLAY_FIELDLIST;
$uid = 0;
$usermode = false;
if (isset($params['uid'])) {
$uid = $params['uid'];
$usermode = true;
}
$fields = self::fieldlist($selected);
@ -219,7 +264,9 @@ class Item extends BaseObject
$condition_string = self::addTablesToFields($condition_string, $threadfields);
$condition_string = self::addTablesToFields($condition_string, $fields);
if ($usermode) {
$condition_string = $condition_string . ' AND ' . self::condition(true);
}
$param_string = dba::buildParameter($params);
$param_string = self::addTablesToFields($param_string, $threadfields);

View File

@ -2104,20 +2104,23 @@ class OStatus
{
$stamp = microtime(true);
$owner = User::getOwnerDataByNick($owner_nick);
if (!$owner) {
return;
}
$cachekey = "ostatus:feed:" . $owner_nick . ":" . $filter . ":" . $last_update;
$previous_created = $last_update;
// Don't cache when the last item was posted less then 15 minutes ago (Cache duration)
if ((time() - strtotime($owner['last-item'])) < 15*60) {
$result = Cache::get($cachekey);
if (!$nocache && !is_null($result)) {
logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created . ' (cached)', LOGGER_DEBUG);
$last_update = $result['last_update'];
return $result['feed'];
}
$owner = User::getOwnerDataByNick($owner_nick);
if (!$owner) {
return;
}
if (!strlen($last_update)) {
@ -2131,10 +2134,6 @@ class OStatus
AND NOT `private` AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
$owner["uid"], $check_date, NETWORK_OSTATUS, NETWORK_DFRN];
if ($filter === 'posts') {
$condition[0] .= " AND `id` = `parent`";
}
if ($filter === 'comments') {
$condition[0] .= " AND `object-type` = ? ";
$condition[] = ACTIVITY_OBJ_COMMENT;
@ -2147,7 +2146,13 @@ class OStatus
}
$params = ['order' => ['created' => true], 'limit' => $max_items];
if ($filter === 'posts') {
$ret = Item::selectThread([], $condition, $params);
} else {
$ret = Item::select([], $condition, $params);
}
$items = dba::inArray($ret);
$doc = new DOMDocument('1.0', 'utf-8');