diff --git a/html/inc/team.inc b/html/inc/team.inc
index 6196f60359..e3512eb711 100644
--- a/html/inc/team.inc
+++ b/html/inc/team.inc
@@ -43,9 +43,8 @@ function display_team_page($team, $offset, $sort_by) {
}
row2("Web site", "$x");
}
- row2("Members (with credit)", team_count_nusers($team->id));
+ row2("Members (with credit)", $team->nusers);
- // Founder object cache
$cache_args = "teamid=".$team->id."&founderid=".$team->userid;
$cached_data = get_cached_data(TEAM_PAGE_TTL, $cache_args);
if ($cached_data){
@@ -178,7 +177,7 @@ function show_team_row($team, $i) {
echo"
$i |
id>$team->name |
- ".team_count_nusers($team->id)." |
+ ".$team->nusers." |
$team_expavg_credit |
$team_total_credit |
$team->country |
diff --git a/html/user/team_display.php b/html/user/team_display.php
index 60c2f81814..b7f5b555c8 100644
--- a/html/user/team_display.php
+++ b/html/user/team_display.php
@@ -15,20 +15,22 @@ if (!$offset) $offset=0;
$teamid = get_int("teamid");
if ($offset > 1000) {
- error_page("Limit exceeded: Only displaying the first 1000 members.");
+ error_page("Limit exceeded: Only displaying the first 1000 members.");
}
db_init();
-// We can only cache team object, as the page is customised to the current user
$user = get_logged_in_user(false);
-
+// We can only cache team object, as the page is customised to the current user
$cache_args = "teamid=$teamid&sort_by=$sort_by&offset=$offset";
$cached_data = get_cached_data(TEAM_PAGE_TTL, $cache_args);
if ($cached_data) {
+ // We found some old but non-stale data, let's use it
$team = unserialize($cached_data);
} else {
+ // No data was found, generate new data for the cache and store it
$team = lookup_team($teamid);
+ $team->nusers = team_count_nusers($team->id);
set_cache_data(serialize($team), $cache_args);
}
diff --git a/html/user/top_teams.php b/html/user/top_teams.php
index efa5824543..1078708d6e 100644
--- a/html/user/top_teams.php
+++ b/html/user/top_teams.php
@@ -64,8 +64,15 @@ if ($offset < ITEM_LIMIT) {
} else { //if not do queries etc to generate new data
db_init();
$data = get_top_teams($offset,$sort_by,$type);
+
+ // We need to calculate nusers before storing into the cache
+ $o = 0;
+ while ($team = $data[$o]) {
+ $data[$o]->nusers = team_count_nusers($team->id);
+ $o++;
+ }
set_cache_data(teams_to_store($data),$cache_args); //save data in cache
- };
+ }
} else {
error_page("Limit exceeded - Sorry, first ".ITEM_LIMIT." items only");
}
@@ -94,5 +101,4 @@ if ($o==ITEMS_PER_PAGE){ //If we aren't on the last page
}
page_tail();
-
?>