Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Optimizing Profiles and Daycare (http://www.mysidiaadoptables.com/forum/showthread.php?t=5082)

Abronsyth 03-21-2016 12:39 PM

Optimizing Profiles and Daycare
 
Hello!

I've noticed that the daycare and user profiles (anywhere where a large amount of pets must be loaded) seems to load extremely slowly on my site. The host itself may be to blame, but it's difficult for me to tell in that regard.

Does anyone possible have some ideas to optimize these features so that they load more quickly? Right now I have the daycare modified to only show 25 pets, and then needs to be reloaded to show more (so no pages), and profiles display pet groups (so not all at once).

RestlessThoughts 03-25-2016 08:33 PM

Well, I have a couple suggestions that may or may not help much. :bucktard:
Probably the easiest way to potentially speed up the pages may be to add suitable indexes to your mysql tables. You can do that from phpmyadmin, going to structure then clicking to add an index on the column.

My index suggestions would be to add an index on the columns in the following tables:
owned_adoptables table - owner, type, possibly currentlevel
adoptables table - type
levels table - adoptiename, thisislevel

These are the columns that the daycare uses to select pet information. If your tables are small, indexes won't help. Also, indexes can slow inserts so don't add too many.

You should also optimize your images as much as you can.

I also wrote a few new functions for the daycare. The daycare code calls the database multiple times per pet displayed, so I used joins to combine the individual calls into one big call for the whole result set. This mostly helps avoid latency. The custom functions also bypass some of the classes since many of the constructors call the database and for ease of use I didn't want to modify more than two files. Also didn't want to directly replace methods, so the result is slight code duplication but this way it can't interfere with anything else on the site.

Anyway, add these three methods to the bottom of your class_daycare.php file, under the getStats method.
PHP Code:

    public function joinedListing() {
        
$mysidia Registry::get('mysidia');
        
$conditions $this->getConditions();
        
$fetchMode $this->getFetchMode($conditions);
        
$stmt $mysidia->db->join('adoptables','owned_adoptables.type = adoptables.type')->join('levels''owned_adoptables.type = levels.adoptiename')->select("owned_adoptables", array(), $conditions.' and '.PREFIX.'owned_adoptables.currentlevel = '.PREFIX.'levels.thisislevel'.$fetchMode);
        
$this->total $stmt->rowCount();
        if(
$this->total == 0) throw new DaycareException("empty");
        
$adopts $stmt->fetchAll(PDO::FETCH_ASSOC);
        
$this->adopts Arrays::fromArray($adopts);
        return 
$this->adopts;
    }

    public function 
getStatsFromArray($adopt) {
        
$stats null;
        foreach(
$this->settings->info as $info)
        {
            
$stats .= $info.': '.$adopt[strtolower($info)].'<br>';
        }
        return 
$stats;
    }

    public function 
getImageFromArray($adopt) {
        if (
$adopt['currentlevel'] == 0) return $adopt['eggimage'];
        if (
$adopt['usealternates'] == 'yes') return $adopt['alternateimage'];
        if (
$adopt['imageurl'] != null) return $adopt['imageurl'];
        return 
$adopt['primaryimage'];
    } 

And assuming you haven't modified the file, replace your levelupview.php daycare method with this one. The code commented out is the original code.
PHP Code:

    public function daycare(){
    
//    $mysidia = Registry::get("mysidia");
        
$document $this->document;
        
$document->setTitle($this->lang->daycare_title);
        
$document->addLangvar($this->lang->daycareTRUE);

        
$daycare $this->getField("daycare");
    
//    $adopts = $daycare->getAdopts();
        
$daycareTable = new Table("daycare"""FALSE);
        
$daycareTable->setBordered(FALSE);

        
// New method call
        
$adopts $daycare->joinedListing();

        
$total $daycare->getTotalAdopts();
        
$index 0;

        for(
$row 0$row $daycare->getTotalRows(); $row++){
            
$daycareRow = new TRow("row{$row}");
            for(
$column 0$column $daycare->getTotalColumns(); $column++){
            
//  $adopt = new OwnedAdoptable($adopts[$index]);

                
$adopt $adopts[$index];
                
$cell = new ArrayList;
            
//    $cell->add(new Link("levelup/click/{$adopt->getAdoptID()}", $adopt->getImage("gui"), TRUE));
            //    $cell->add(new Comment($daycare->getStats($adopt)));

                // New display calls.
                
$cell->add(new Link("levelup/click/{$adopt['aid']}""<img src='{$daycare->getImageFromArray($adopt)}'>"TRUE));
                
$cell->add(new Comment($daycare->getStatsFromArray($adopt)));

                
$daycareCell = new TCell($cell"cell{$index}");
                
$daycareCell->setAlign(new Align("center""center"));
                
$daycareRow->add($daycareCell);
                
$index++;
                if(
$index == $total) break;
            }
            
$daycareTable->add($daycareRow);
        }

        
$document->add($daycareTable);
        if(
$pagination $daycare->getPagination()) $document->addLangvar($pagination->showPage());
    } 

Let me know if these suggestions help any, or if you run into trouble implementing them.

Abronsyth 03-26-2016 01:41 AM

Well, the daycare loading speed is vastly improved! Absolutely brilliant, thank you so very much! Damned thing was driving me crazy!

I'm still looking over the profiles and seeing what I can do there, haha.


All times are GMT -5. The time now is 10:17 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.