Skip to content

Commit

Permalink
issue105: improve performance around the uselogs option #105 (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwalits authored Feb 23, 2020
1 parent 08a3e7b commit baa151a
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,14 @@ function tool_crawler_crawl($verbose = false) {
$crawlstart = $config->crawlstart;
$crawlend = $config->crawlend;

if ($config->uselogs == 1) {
$recentcourses = $robot->get_recentcourses();
}

// If we need to start a new crawl, add new items to the queue.
if (!$crawlstart || $crawlstart <= $crawlend) {

$start = time();
set_config('crawlstart', $start, 'tool_crawler');

if ($config->uselogs == 1) {
$recentcourses = $robot->get_recentcourses();
foreach ($recentcourses as $courseid) {
$robot->mark_for_crawl($CFG->wwwroot . '/', 'course/view.php?id=' . $courseid, $courseid);
}
Expand All @@ -74,25 +71,6 @@ function tool_crawler_crawl($verbose = false) {
$history = $DB->get_record('tool_crawler_history', array('startcrawl' => $crawlstart));
}

// Before beginning to process queue, add any new courses to the queue.
if ($config->uselogs == 1) {

$coursesinurltableobject = $DB->get_records_list('tool_crawler_url', 'courseid', $recentcourses, '', 'DISTINCT courseid');

$coursesinurltable = [];
foreach ($coursesinurltableobject as $course) {
array_push($coursesinurltable, $course->courseid);
}

foreach ($recentcourses as $courseid) {

// If a course from recent activity is not in the queue, add it.
if (!in_array($courseid, $coursesinurltable)) {
$robot->mark_for_crawl($CFG->wwwroot . '/', 'course/view.php?id=' . $courseid, $courseid);
}
}
}

$cronstart = time();
$cronstop = $cronstart + $config->maxcrontime;

Expand Down

0 comments on commit baa151a

Please sign in to comment.