Every time I upgrade there's massive performance issues. This time round it's to do with Photos and the fact your system needs to go through every single photo in the database one by one, every time a page is loaded. I don't understand why you program in half the stuff you do.
All I did was upgrade then I started getting massive system alerts and my server was about to crash. Turns out it's the following method:
com_community/models/photos.php - _getAlbums()
It runs this on every page load, or at least every profile. Gets every album from the databases then one by one gets every photo from the database (over 30,000 database calls per page load). Look at the New Relic stats!
I've had to comment out the entire method and return an empty array otherwise it crashes my site.
What's the problem? What's the use of this method and why do you feel it's required on each page load?
public function _getAlbums($id, $type, $pagination = false, $doubleLimit = false, $limit = "", $creator = '', $sort = 'date', $excludeType = array()) {
// $db = $this->getDBO();
// $extraSQL = ' WHERE a.type != ' . $db->Quote('');
//
// if (!empty($id) && $type == PHOTOS_GROUP_TYPE) {
// $extraSQL .= ' AND a.groupid=' . $db->Quote($id) . ' ';
// if (!empty($creator)) {
// $extraSQL .= ' AND a.creator=' . $db->Quote($creator) . ' ';
// }
// } else if (!empty($id) && $type == PHOTOS_USER_TYPE) {
// $extraSQL .= ' AND a.creator=' . $db->Quote($id) . ' ';
// // privacy
//
// $permission = CPrivacy::getAccessLevel(null, $id);
// $extraSQL .= ' AND a.permissions <=' . $db->Quote($permission) . ' ';
// }else if( !empty($id) && $type == PHOTOS_PROFILE_TYPE ){
// $extraSQL .= ' AND a.creator=' . $db->Quote($id)
// .' AND a.groupid=' . $db->Quote(0) . ' AND a.eventid= '. $db->Quote(0)
// .' AND a.type <> '.$db->quote('profile.cover');
// }
//
// if(count($excludeType) > 0){
// foreach($excludeType as $type){
// $extraSQL .= ' AND a.type != '.$db->Quote($type).' ';
// }
// }
//
// // Get limit
// $limit = (!empty($limit)) ? $limit : $this->getState('limit');
// $limit = ( $doubleLimit ) ? $this->getState('limit') : $limit;
// $limitstart = $this->getState('limitstart');
//
// // Get total albums
// $total = $this->getAlbumCount($extraSQL);
// $this->total = $total;
//
// //special case for featured only, it must not be paginated
// if($sort == 'featured'){
// $featured = new CFeatured(FEATURED_ALBUMS);
// $featuredAlbums = implode(',',$featured->getItemIds());
// $order = " ORDER BY (a.`id` IN (".$featuredAlbums.")) DESC, a.id ";
// $result = ($pagination) ? $this->getAlbumPhotoCount($extraSQL, $limit, $limitstart,$order ) : $this->getAlbumPhotoCount($extraSQL, null, null, $order);
//
// }elseif($sort == 'featured_only'){
// $result = $this->getAlbumPhotoCount($extraSQL, NULL, NULL, ' ORDER BY `name` ASC');
// }elseif($sort == 'name'){
// $result = ($pagination) ? $this->getAlbumPhotoCount($extraSQL, $limit, $limitstart, ' ORDER BY `name` ASC') : $this->getAlbumPhotoCount($extraSQL, NULL, NULL, ' ORDER BY `name` ASC');
// }elseif($sort == 'hit') {
// $result = ($pagination) ? $this->getAlbumPhotoCount($extraSQL, $limit, $limitstart, ' ORDER BY `hits` DESC') : $this->getAlbumPhotoCount($extraSQL, null, null, ' ORDER BY `hits` DESC');
// }else{
// $result = ($pagination) ? $this->getAlbumPhotoCount($extraSQL, $limit, $limitstart) : $this->getAlbumPhotoCount($extraSQL);
// }
/* filter results, album that has photos + all unpublished = not to be displayed
* album that has no photos = display
*/
// foreach ($result as $key => $res) {
// $temp = $this->getPhotos($res->id, null, null, true);
// $hasPhoto = true; //assume all photo is temp
//
// if (count($temp) > 0) {
// foreach ($temp as $tempPhoto) {
// if ($tempPhoto->published == 1) {
// $hasPhoto = false; // this album has photos, show this album
// break;
// } elseif($tempPhoto->published == 0 && $tempPhoto->status =="delete") {
// $hasPhoto = false; // this album has photos, show this album
// break;
// }
// }
// } else {
// $hasPhoto = false;
// }
//
// if ($hasPhoto) {
// unset($result[$key]);
// }
// }
// $result = [];
//
// // Update their correct Thumbnails
// $this->_updateThumbnail($result);
//
// //sort the albums
// $data = $this->sortAlbums($result,$sort);
//
//
// // Apply pagination based on counted data
// if($limit > count($data) && empty($this->_pagination)){
// jimport('joomla.html.pagination');
// $this->_pagination = new JPagination(count($data), $limitstart, $limit);
// }else{
// $this->_pagination = new JPagination($total, $limitstart, $limit);
// }
$tmpData = array();
// if ($type == PHOTOS_PROFILE_TYPE) {
// $type = PHOTOS_USER_TYPE;
// }
//
// foreach ($data as $_data) {
// if ( ( $_data->default == 1 ) && ( $type == $_data->type ) && $sort != 'hit' ) {
// array_unshift($tmpData, $_data);
// } else {
// $tmpData[] = $_data;
// }
// }
return $tmpData;
}
Hi, Wasim.
Thank you for reporting this issue.
I assign developer to review it.
Hello Wasim
We have tried to investigate the issue but couldn't do it properly because of environment issues.
Would it be okay for you to setup the staging shadow copy site on your server and provides the full access to it, so we can run tests and optimizations directly at the problematic site.
You can also reach me to sinisa AT ijoomla DOT com
I've be looking forward to your reply
I don't think I'm going to do that. My server is not a guinea pig to run tests on. I'm sorry if you are unable to fix the problem without that but I'm not going to purposely cause the server load and risk downtime or reduced performance for the rest of the site. If there's anything else I can do let me know.