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;
/**
* @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);
$condition_string = self::addTablesToFields($condition_string, $threadfields);
$condition_string = self::addTablesToFields($condition_string, $fields);
- $condition_string = $condition_string . ' AND ' . self::condition(true);
+ if ($usermode) {
+ $condition_string = $condition_string . ' AND ' . self::condition(true);
+ }
$param_string = dba::buildParameter($params);
$param_string = self::addTablesToFields($param_string, $threadfields);
{
$stamp = microtime(true);
+ $owner = User::getOwnerDataByNick($owner_nick);
+ if (!$owner) {
+ return;
+ }
+
$cachekey = "ostatus:feed:" . $owner_nick . ":" . $filter . ":" . $last_update;
$previous_created = $last_update;
- $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;
+ // 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'];
+ }
}
if (!strlen($last_update)) {
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;
}
$params = ['order' => ['created' => true], 'limit' => $max_items];
- $ret = Item::select([], $condition, $params);
+
+ 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');