Skip to content

Commit 756d06e

Browse files
committed
Add documentation to optim guide
1 parent 17b821e commit 756d06e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

documentation/optimization.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,38 @@ <h2><a name="1.Using-XCache"></a>1. Using xCache or APC</h2>
245245
...
246246
}
247247
</pre>
248+
Finally, the Free Campus of Chamilo has a very specific case of slow query: the courses catalog! Because there might be more than 30,000 courses in there, getting the number of "Connections last month" can be a desastrous query in terms of performances. This is why you should try to cache the results as well.<br />
249+
Obviously, as we are speaking about showing the number of visits this month, it doesn't really matter if the number doesn't refresh for an hour or so...<br />
250+
Locate the main/inc/lib/course_category.lib.php file, open it and go to the browseCoursesInCategory() function.<br />
251+
Locate the $count_connections_last_month = Tracking::get_course_connections_count(...) call, and wrap in into something like this:
252+
<pre>
253+
$xc = method_exists('Memcached', 'add');
254+
if ($xc) {
255+
// Make sure the server is available
256+
$xm = new Memcached;
257+
$xm->addServer('localhost', 11211);
258+
// The following concatenates the name of the database + the id of the
259+
// access url to make it a unique variable prefix for the variables to
260+
// be stored
261+
$xs = $_configuration['main_database'].'_'.$_configuration['access_url'].'_';
262+
}
263+
$result = Database::query($sql);
264+
$courses = array();
265+
while ($row = Database::fetch_array($result)) {
266+
$row['registration_code'] = !empty($row['registration_code']);
267+
$count_users = CourseManager::get_users_count_in_course($row['code']);
268+
if ($xc) {
269+
if ($xm->get($xs.'cccount_'.$row['code'])) {
270+
$number = $xm->get($xs.'cccount_'.$row['code']);
271+
} else {
272+
$count_connections_last_month = Tracking::get_course_connections_count($row['code'], 0, api_get_utc_datetime(time() - (30 * 86400)));
273+
$xm->set($xs.'cccount_'.$row['code'], $count_connections_last_month, 3600);
274+
}
275+
} else {
276+
$count_connections_last_month = Tracking::get_course_connections_count($row['code'], 0, api_get_utc_datetime(time() - (30 * 86400)));
277+
}
278+
...
279+
</pre>
248280
<hr />
249281
<h2><a name="2.Slow-queries"></a>2. Slow queries</h2>
250282
Enable slow_queries in /etc/mysqld/my.cnf, restart MySQL then follow using sudo tail -f /var/log/mysql/mysql-slow.log

0 commit comments

Comments
 (0)