diff --git a/include/Photo.php b/include/Photo.php index 3ab374bd0b..e734fed89a 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -1065,6 +1065,16 @@ function store_photo($a, $uid, $imagedata = "", $url = "") { return($image); } +/** + * @brief Fetch the photo albums that are available for a viewer + * + * The query in this function is cost intensive, so it is cached. + * + * @param int $uid User id of the photos + * @param bool $update Update the cache + * + * @return array Returns array of the photo albums + */ function photo_albums($uid, $update = false) { $sql_extra = permissions_sql($uid); @@ -1073,7 +1083,7 @@ function photo_albums($uid, $update = false) { if (is_null($albums) OR $update) { /// @todo This query needs to be renewed. It is really slow // At this time we just store the data in the cache - $albums = qu("SELECT count(distinct `resource-id`) AS `total`, `album` + $albums = qu("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album` FROM `photo` USE INDEX (`uid_album_created`) WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra GROUP BY `album` ORDER BY `created` DESC", diff --git a/include/dbstructure.php b/include/dbstructure.php index 3d14615327..3826716c54 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -587,6 +587,7 @@ function db_definition($charset) { ), "indexes" => array( "PRIMARY" => array("id"), + "cmd_item_contact" => array("UNIQUE", "cmd", "item", "contact"), ) ); $database["event"] = array( diff --git a/include/socgraph.php b/include/socgraph.php index e1b5cdbf9a..349869c406 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1115,7 +1115,7 @@ function suggestion_query($uid, $start = 0, $limit = 80) { intval($limit) ); - if(count($r) && count($r) >= ($limit -1)) { + if (count($r) && count($r) >= ($limit -1)) { Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $r, CACHE_FIVE_MINUTES); return $r; } diff --git a/include/threads.php b/include/threads.php index a487d6e01f..79340ab2cb 100644 --- a/include/threads.php +++ b/include/threads.php @@ -22,6 +22,15 @@ function add_thread($itemid, $onlyshadow = false) { } } +/** + * @brief Add a shadow entry for a given item id + * + * We store every public item entry additionally with the user id "0". + * This is used for the community page and for the search. + * It is planned that in the future we will store public item entries only once. + * + * @param integer $itemid Item ID that should be added + */ function add_shadow_thread($itemid) { $items = q("SELECT `uid`, `wall`, `private`, `moderated`, `visible`, `contact-id`, `deleted`, `network` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));