New item functions, improved feed cache behaviour
This commit is contained in:
parent
4714cb746b
commit
ebd76285d8
2 changed files with 75 additions and 23 deletions
|
@ -164,21 +164,63 @@ class Item extends BaseObject
|
||||||
return dba::p($sql, $condition);
|
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
|
* 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
|
* @brief Retrieve a single record from a table
|
||||||
* @param integer $uid User ID
|
* @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 $fields
|
||||||
* @param array $condition
|
* @param array $condition
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @return bool|array
|
* @return bool|array
|
||||||
* @see dba::select
|
* @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;
|
$params['limit'] = 1;
|
||||||
$result = self::selectThreadForUser($uid, $fields, $condition, $params);
|
$result = self::selectThread($fields, $condition, $params);
|
||||||
|
|
||||||
if (is_bool($result)) {
|
if (is_bool($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -192,17 +234,20 @@ class Item extends BaseObject
|
||||||
/**
|
/**
|
||||||
* @brief Select rows from the starting post in the item table
|
* @brief Select rows from the starting post in the item table
|
||||||
*
|
*
|
||||||
* @param integer $uid User ID
|
* @param array $selected Array of selected fields, empty for all
|
||||||
* @param array $fields Array of selected fields, empty for all
|
|
||||||
* @param array $condition Array of fields for condition
|
* @param array $condition Array of fields for condition
|
||||||
* @param array $params Array of several parameters
|
* @param array $params Array of several parameters
|
||||||
*
|
*
|
||||||
* @return boolean|object
|
* @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)) {
|
$uid = 0;
|
||||||
$selected = Item::DISPLAY_FIELDLIST;
|
$usermode = false;
|
||||||
|
|
||||||
|
if (isset($params['uid'])) {
|
||||||
|
$uid = $params['uid'];
|
||||||
|
$usermode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = self::fieldlist($selected);
|
$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, $threadfields);
|
||||||
$condition_string = self::addTablesToFields($condition_string, $fields);
|
$condition_string = self::addTablesToFields($condition_string, $fields);
|
||||||
|
|
||||||
|
if ($usermode) {
|
||||||
$condition_string = $condition_string . ' AND ' . self::condition(true);
|
$condition_string = $condition_string . ' AND ' . self::condition(true);
|
||||||
|
}
|
||||||
|
|
||||||
$param_string = dba::buildParameter($params);
|
$param_string = dba::buildParameter($params);
|
||||||
$param_string = self::addTablesToFields($param_string, $threadfields);
|
$param_string = self::addTablesToFields($param_string, $threadfields);
|
||||||
|
|
|
@ -2104,20 +2104,23 @@ class OStatus
|
||||||
{
|
{
|
||||||
$stamp = microtime(true);
|
$stamp = microtime(true);
|
||||||
|
|
||||||
|
$owner = User::getOwnerDataByNick($owner_nick);
|
||||||
|
if (!$owner) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$cachekey = "ostatus:feed:" . $owner_nick . ":" . $filter . ":" . $last_update;
|
$cachekey = "ostatus:feed:" . $owner_nick . ":" . $filter . ":" . $last_update;
|
||||||
|
|
||||||
$previous_created = $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);
|
$result = Cache::get($cachekey);
|
||||||
if (!$nocache && !is_null($result)) {
|
if (!$nocache && !is_null($result)) {
|
||||||
logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created . ' (cached)', LOGGER_DEBUG);
|
logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created . ' (cached)', LOGGER_DEBUG);
|
||||||
$last_update = $result['last_update'];
|
$last_update = $result['last_update'];
|
||||||
return $result['feed'];
|
return $result['feed'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$owner = User::getOwnerDataByNick($owner_nick);
|
|
||||||
if (!$owner) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strlen($last_update)) {
|
if (!strlen($last_update)) {
|
||||||
|
@ -2131,10 +2134,6 @@ class OStatus
|
||||||
AND NOT `private` AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
|
AND NOT `private` AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
|
||||||
$owner["uid"], $check_date, NETWORK_OSTATUS, NETWORK_DFRN];
|
$owner["uid"], $check_date, NETWORK_OSTATUS, NETWORK_DFRN];
|
||||||
|
|
||||||
if ($filter === 'posts') {
|
|
||||||
$condition[0] .= " AND `id` = `parent`";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($filter === 'comments') {
|
if ($filter === 'comments') {
|
||||||
$condition[0] .= " AND `object-type` = ? ";
|
$condition[0] .= " AND `object-type` = ? ";
|
||||||
$condition[] = ACTIVITY_OBJ_COMMENT;
|
$condition[] = ACTIVITY_OBJ_COMMENT;
|
||||||
|
@ -2147,7 +2146,13 @@ class OStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
$params = ['order' => ['created' => true], 'limit' => $max_items];
|
$params = ['order' => ['created' => true], 'limit' => $max_items];
|
||||||
|
|
||||||
|
if ($filter === 'posts') {
|
||||||
|
$ret = Item::selectThread([], $condition, $params);
|
||||||
|
} else {
|
||||||
$ret = Item::select([], $condition, $params);
|
$ret = Item::select([], $condition, $params);
|
||||||
|
}
|
||||||
|
|
||||||
$items = dba::inArray($ret);
|
$items = dba::inArray($ret);
|
||||||
|
|
||||||
$doc = new DOMDocument('1.0', 'utf-8');
|
$doc = new DOMDocument('1.0', 'utf-8');
|
||||||
|
|
Loading…
Reference in a new issue