[v3]裝備商店快取

提供WOG各方面的技術問題,並提供最新path更新。

版主: 涅魂, 簫哥, 10度C~

stu6707
 
文章: 162
註冊時間: 2008-10-26 1:00 pm

[v3]裝備商店快取

文章stu6707 » 2011-05-02 6:07 pm

如題,建立商店裝備txt快取,速度比從資料庫抓取快了不少

測試數據(單位 sec)
without cache
tested times - 45
shortest - 0.00677490234375
longest - 0.0105791091919
average time - 0.00793019930522

with cache
tested times - 46
shortest - 0.00223398208618
longest - 0.00333404541016
average time - 0.00246748198634


發現bug或是錯誤請回報~ 謝謝~

這邊提供把所有裝備資料存入txt文檔以及讀取文檔的代碼

把裝備資料存入txt
修改 wog_act_shop.php -> shop()
說明:
第一個迴圈($i)是裝備種類 d_type
第二個($a)是裝備等級 d_lv
第三個($b)是裝備頁數
對應三個陣列(item_type,item_lv,item_page),另外item_lv的第一個震列值為空,方便直接抓取應對等級裝備
item_page的第一個值為該裝備等級的總數,給js計算頁數
代碼: 選擇全部
      $data=fopen("shop_cache.txt",'a+');
      $item_type=array();
      for($i=0;$i<6;$i++)
      {
         $type=$i==5?'5,6':$i;
         $item_lv=array();
         $item_lv[]="";
         for($a=1;$a<8;$a++)
         {
            $total="";
            $df_total=$DB_site->query_first("select count(d_id) as d_id from wog_df where d_type in (".$type.") and d_lv=".$a." and d_dbst=0");
            if($df_total){$total=$df_total['d_id'];}
            $item_page=array();
            $item_page[]=$total;
            unset($df_total);
            for($b=1;$b<4;$b++)
            {
               $spage=($b*8)-8;
               $shop=$DB_site->query("select a.d_id,a.d_df,a.d_mdf,a.d_agl,a.d_money,a.d_name,a.d_at,a.d_mat,a.d_mstr,a.d_magl,a.d_msmart,b.ch_name from wog_df a left join wog_character b on b.ch_id=a.ch_id where a.d_type in ($type) and a.d_lv=$a and a.d_dbst=0 LIMIT ".$spage.",8");
               $s="";
               while($shops=$DB_site->fetch_array($shop))
               {
                  $s.=";".$shops[d_id].",".$shops[d_df].",".$shops[d_mdf].",".$shops[d_agl].",".$shops[d_money].",".$shops[d_name].",".$shops[d_at].",".$shops[d_mat].",".$shops[d_mstr].",".$shops[d_magl].",".$shops[d_msmart].",".$shops[ch_name];
               }
               $s=substr($s,1,strlen($s));
               if(strlen($s) > 1)
               {
                  $item_page[$b]=$s;
               }
            }
            $item_pages=implode('#',$item_page);
            if(strlen($item_pages) > 1)
            {
               $item_lv[$a]=$item_pages;
            }
         }
         $item_lvs=implode('@',$item_lv);
         if(strlen($item_lvs) > 5)
         {
            $item_type[$i]=$item_lvs;
         }
         fputs($data,$item_type[$i]."\r\n");
      }
      fclose($data);

快取建立後可以把上面的代碼刪除,換上讀取資料的代碼
代碼: 選擇全部
      $data=file("shop_cache.txt");
      $data_type=trim($data[$_POST["temp_id"]]);
      $data_lv=explode("@",$data_type);
      $data_page=explode("#",$data_lv[$_POST["temp_id2"]]);
      if(empty($_POST["page"]))
      {
         $_POST["page"]="1";
      }
      $s=$data_page[$_POST["page"]];
      $df_total=$data_page[0];
      check_type($_POST["temp_id"],1);


另外把原先取得當前裝備的裝備數值query換成
代碼: 選擇全部
$packs=$DB_site->query_first("select a.d_df,a.d_mdf,a.d_agl,a.d_name,a.d_at,a.d_mat from wog_df a,wog_player b where a.d_id=b.$a_id and b.p_id=".$user_id);

$ss保持不變
showscript改成
代碼: 選擇全部
showscript("parent.shop_home_view('$s','".$_POST["act"]."','".$_POST["temp_id"]."','".$ss."','".$_POST["temp_id2"]."',".$df_total.",".$_POST["page"].")");

其它原先代碼可以刪除

最後一步,修改wog.js

代碼: 選擇全部
<input type="button" value="道具屋" onClick="parent.th_submit(document.f1,1,\'5,6\')">

換成
代碼: 選擇全部
<input type="button" value="道具屋" onClick="parent.th_submit(document.f1,1,5)">


儲存關閉



回到 Online FF Battle-WOG官方聯盟推廣處

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 7 位訪客

cron