Project

General

Profile

Actions

Enhancement(機能追加・改善) #3650

open

#1859 での修正においてコミュニティカテゴリのソートのパフォーマンス向上の対応を行う

Added by Shinichi Urabe over 10 years ago. Updated almost 5 years ago.

Status:
New(新規)
Priority:
Normal(通常)
Assignee:
-
Target version:
Start date:
2014-07-08
Due date:
% Done:

0%

Estimated time:

Description

概要

https://redmine.openpne.jp/issues/1859#note-8 を引用

このあたりが非効率な気がしました.
一旦ルートとその子供をそれぞれ取る必要はなく,ソートされた状態のルートから ソートされた子供が取得できるため,これを順番に配列に追加してゆけば問題ないのではないかと思います.

パフォーマンスについては,DB 接続やソートのオーダーを無視したとして,下記のものだと 子供の数 m と 親の数 n としたときにビックオー記法で O(n+m) となります.これはおそらく O(m) になるものと思います.実際に測定しないと効果がわからいませんが,コード上ではここに記述したとおりの解釈となると思います.

lib/model/doctrine/CommunityCategoryTable.class.php

 52   public function getAllChildren($checkIsAllowMemberCommunity = false)
 53   {
 54     $roots = $this->retrieveAllRoots();
 55     $children = $this->retrieveAllChildren();
 56 
 57     // sort by root category
 58     $temp = array();
 59     foreach ($children as $child)
 60     {
 61       if ($checkIsAllowMemberCommunity && !$child->getIsAllowMemberCommunity())
 62       {
 63         continue;
 64       }
 65       $temp[$child->getTreeKey()][] = $child;
 66     }
 67 
 68     $data = array();
 69     foreach ($roots as $root)
 70     {
 71       if (isset($temp[$root->getId()]))
 72       {
 73         $data = array_merge($data, $temp[$root->getId()]);
 74       }
 75     }
 76 
 77     $collection = new Doctrine_Collection($this);
 78     $collection->setData($data);
 79 
 80     return $collection;
 81   }

仕様

Actions #1

Updated by kaoru n almost 8 years ago

  • Target version changed from OpenPNE 3.9.0-old to OpenPNE 3.9.0
Actions #2

Updated by kaoru n almost 5 years ago

  • Target version changed from OpenPNE 3.9.0 to OpenPNE 3.10.x
Actions

Also available in: Atom PDF