View Single Post
  #2  
Old 03-25-2016, 08:33 PM
RestlessThoughts's Avatar
RestlessThoughts RestlessThoughts is offline
Member
 
Join Date: Mar 2016
Posts: 10
Gender: Female
Credits: 1,233
RestlessThoughts is on a distinguished road
Default

Well, I have a couple suggestions that may or may not help much.
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.
Reply With Quote