Skip to content

Commit

Permalink
Add performance logging to threading
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Jul 7, 2020
1 parent 79e35a3 commit 0fd1cd7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions lib/IMAP/Threading/ThreadBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,48 @@

namespace OCA\Mail\IMAP\Threading;

use OCA\Mail\Support\PerformanceLogger;
use function array_key_exists;
use function count;

class ThreadBuilder {

/** @var PerformanceLogger */
private $performanceLogger;

public function __construct(PerformanceLogger $performanceLogger) {
$this->performanceLogger = $performanceLogger;
}

/**
* @param Message[] $messages
*
* @return Container[]
*/
public function build(array $messages): array {
$log = $this->performanceLogger->start('Threading ' . count($messages) . ' messages');

// Step 1
$idTable = $this->buildIdTable($messages);
$log->step('build ID table');

// Step 2
$rootContainer = $this->buildRootContainer($idTable);
$log->step('build root container');

// Step 3
unset($idTable);
$log->step('free ID table');

// Step 4
$this->pruneContainers($rootContainer);
$log->step('prune containers');

// Step 5
$this->groupBySubject($rootContainer);
$log->step('group by subject');

$log->end();
// Return the children with reset numeric keys
return array_values($rootContainer->getChildren());
}
Expand Down
12 changes: 10 additions & 2 deletions tests/Unit/IMAP/Threading/ThreadBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,25 @@
use OCA\Mail\IMAP\Threading\Container;
use OCA\Mail\IMAP\Threading\Message;
use OCA\Mail\IMAP\Threading\ThreadBuilder;
use function array_values;
use OCA\Mail\Support\PerformanceLogger;
use PHPUnit\Framework\MockObject\MockObject;

class ThreadBuilderTest extends TestCase {

/** @var PerformanceLogger|MockObject */
private $performanceLogger;

/** @var ThreadBuilder */
private $builder;

protected function setUp(): void {
parent::setUp();

$this->builder = new ThreadBuilder();
$this->performanceLogger = $this->createMock(PerformanceLogger::class);

$this->builder = new ThreadBuilder(
$this->performanceLogger
);
}

/**
Expand Down

0 comments on commit 0fd1cd7

Please sign in to comment.