Skip to content

Commit cf1953f

Browse files
committed
fix: add cache to sql queries
1 parent ad6830f commit cf1953f

1 file changed

Lines changed: 34 additions & 21 deletions

File tree

openstack/code/CompanyListPage.php

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,40 +82,53 @@ public function EditorToolbar() {
8282

8383
function DisplayedCompanies($type)
8484
{
85-
if ($type == 'Combined') {
86-
87-
$DisplayedCompanies = Company::get()->filter(array( 'DisplayOnSite' => 1 ))->filterAny( array( 'MemberLevel' => array('Startup','Silver') ))->sort('Name');
88-
89-
} else {
90-
91-
$DisplayedCompanies = Company::get()->filter(array('DisplayOnSite' => 1, 'MemberLevel' => $type ))->sort('Name');
92-
}
93-
if ($DisplayedCompanies) {
94-
return $DisplayedCompanies;
95-
} else {
96-
return NULL;
85+
$cache = SS_Cache::factory('cache_company_list_page');
86+
$list = unserialize($cache->load('var_cache_company_list_page_displayed_companies_' . $type));
87+
if (!$list) {
88+
if ($type == 'Combined') {
89+
$list = Company::get()->filter(array('DisplayOnSite' => 1))->filterAny(array('MemberLevel' => array('Startup', 'Silver')))->sort('Name');
90+
} else {
91+
$list = Company::get()->filter(array('DisplayOnSite' => 1, 'MemberLevel' => $type))->sort('Name');
92+
}
93+
$cache->save(serialize($list), 'var_cache_company_list_page_displayed_companies_' . $type);
9794
}
95+
if(!$list) $list = NULL;
96+
return $list;
9897
}
9998

10099
function MostRecent()
101100
{
102-
103-
$DisplayedCompanies = Company::get()->filter(array('DisplayOnSite' => 1))->sort('Name');
104-
$DisplayedCompanies->sort('Created');
105-
$MostRecent = $DisplayedCompanies->Last();
106-
return $MostRecent;
101+
$cache = SS_Cache::factory('cache_company_list_page');
102+
$most_recent = unserialize($cache->load('var_cache_company_list_page_most_recent'));
103+
if(!$most_recent){
104+
$list = Company::get()->filter(array('DisplayOnSite' => 1))->sort('Name');
105+
$list->sort('Created');
106+
$most_recent = $list->Last();
107+
$cache->save(serialize($most_recent), 'var_cache_company_list_page_most_recent');
108+
}
109+
return $most_recent;
107110
}
108111

109112
function Featured()
110113
{
111-
$FeaturedCompanies = Company::get()->filter('Featured' , 1)->sort('Name');
112-
return $FeaturedCompanies;
114+
$cache = SS_Cache::factory('cache_company_list_page');
115+
$list = unserialize($cache->load('var_cache_company_list_page_featured'));
116+
if(!$list) {
117+
$list = Company::get()->filter('Featured', 1)->sort('Name');
118+
$cache->save(serialize($list), 'var_cache_company_list_page_featured');
119+
}
120+
return $list;
113121
}
114122

115123
function getDonorsOrdered()
116124
{
117-
$DonorCompanies = $this->Donors()->sort('SortOrder');
118-
return $DonorCompanies;
125+
$cache = SS_Cache::factory('cache_company_list_page');
126+
$list = unserialize($cache->load('var_cache_company_list_donors_ordered'));
127+
if(!$list) {
128+
$list = $this->Donors()->sort('SortOrder');
129+
$cache->save(serialize($list), 'var_cache_company_list_donors_ordered');
130+
}
131+
return $list;
119132
}
120133

121134
//Show the Company detail page using the CompanyListPage_show.ss template

0 commit comments

Comments
 (0)