データベース呼び出しによってページの読み込みが大幅に遅くなるという問題が発生しています。選挙データから複数のグラフを生成しています。テーブルには約 100 万行が含まれており、メソッド内の各メソッドでこのデータを複数回クエリする必要がありますgetCharts()
。
これを使用して、戻りデータを JavaScript に渡します。
これらのグラフは、データ ポイントをクリックすると再入力されます。つまり、ポイント ('democrat) をクリックすると、ページがリロードされ、これらのメソッドが再度呼び出されます。
私が求めているのは、ネイティブ PHP でこのようなことができるかどうかです。サーバーは、linode で PHP 5.2 を実行しています。
foreach(function in getChartsMethod){
Start a child thread to process the function.
}
join the threads.
reload the page.
public function getCharts(){
$this->get_cast_chart();
$this->get_party_chart();
$this->get_gender_chart();
$this->get_age_chart();
$this->get_race_chart();
$this->get_ballot_chart();
$this->get_county_chart();
$this->get_precinct_chart();
$this->get_congressional_district_chart();
$this->get_senate_district_chart();
$this->get_house_district_chart();
return view('elections.index');
}
サンプル方法
public function get_party_chart(){
$query = DB::table($this->tableName)
->select('party', DB::raw('count(*) as numVotes'))
->groupBy('party')
->orderBy('numVotes', 'ASC');
if ($this->filterParameters != null){
$query = $query->where(key($this->filterParameters), $this->operator, current($this->filterParameters));
}
$chartData = $query->get();
$chartData = $this->prepare_data_for_chart($chartData, 'party', 'numVotes');
JavaScript::put(['partyChart' => $chartData]);
}