Skip to content

Commit 8e7ae7b

Browse files
author
vrana
committed
Optimize reindex_everything.php
Summary: We have two troubles with this script: # Our revisions and commits don't fit in the memory. (Our tasks do :-).) # Reindexing revisions is slow. Test Plan: Ran it. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3483
1 parent 3c2cb13 commit 8e7ae7b

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

scripts/search/reindex_everything.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?php
33

44
/*
5-
* Copyright 2011 Facebook, Inc.
5+
* Copyright 2012 Facebook, Inc.
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -23,34 +23,28 @@
2323
// TODO: Get rid of this script eventually, once this stuff is better-formalized
2424
// in Timeline consumers.
2525

26-
echo "Loading revisions...\n";
27-
$revs = id(new DifferentialRevision())->loadAll();
28-
$count = count($revs);
29-
echo "Reindexing {$count} revisions";
26+
echo "Reindexing revisions...\n";
27+
$revs = new LiskMigrationIterator(new DifferentialRevision());
3028
foreach ($revs as $rev) {
3129
PhabricatorSearchDifferentialIndexer::indexRevision($rev);
3230
echo '.';
3331
}
3432
echo "\n";
3533

36-
echo "Loading commits...\n";
37-
$commits = id(new PhabricatorRepositoryCommit())->loadAll();
38-
$count = count($commits);
39-
echo "Reindexing {$count} commits";
34+
echo "Reindexing commits...\n";
35+
$commits = new LiskMigrationIterator(new PhabricatorRepositoryCommit());
4036
foreach ($commits as $commit) {
4137
PhabricatorSearchCommitIndexer::indexCommit($commit);
4238
echo '.';
4339
}
4440
echo "\n";
4541

46-
echo "Loading tasks...\n";
47-
$tasks = id(new ManiphestTask())->loadAll();
48-
$count = count($tasks);
49-
echo "Reindexing {$count} tasks";
42+
echo "Reindexing tasks...\n";
43+
$tasks = new LiskMigrationIterator(new ManiphestTask());
5044
foreach ($tasks as $task) {
5145
PhabricatorSearchManiphestIndexer::indexTask($task);
5246
echo '.';
5347
}
5448
echo "\n";
55-
echo "Done.\n";
5649

50+
include dirname(__FILE__).'/reindex_all_users.php';

src/applications/search/index/indexer/PhabricatorSearchDifferentialIndexer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public static function indexRevision(DifferentialRevision $rev) {
5252
time());
5353
}
5454

55-
$comments = id(new DifferentialComment())->loadAllWhere(
56-
'revisionID = %d',
57-
$rev->getID());
55+
$comments = $rev->loadRelatives(new DifferentialComment(), 'revisionID');
5856

59-
$inlines = id(new DifferentialInlineComment())->loadAllWhere(
60-
'revisionID = %d AND commentID IS NOT NULL',
61-
$rev->getID());
57+
$inlines = $rev->loadRelatives(
58+
new DifferentialInlineComment(),
59+
'revisionID',
60+
'getID',
61+
'(commentID IS NOT NULL)');
6262

6363
$touches = array();
6464

src/infrastructure/storage/lisk/LiskMigrationIterator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ final class LiskMigrationIterator extends PhutilBufferedIterator {
3333

3434
private $object;
3535
private $cursor;
36+
private $set;
3637

3738
public function __construct(LiskDAO $object) {
38-
$this->object = $object;
39+
$this->set = new LiskDAOSet();
40+
$this->object = $object->putInSet($this->set);
3941
}
4042

4143
protected function didRewind() {
@@ -47,6 +49,8 @@ public function key() {
4749
}
4850

4951
protected function loadPage() {
52+
$this->set->clearSet();
53+
5054
$results = $this->object->loadAllWhere(
5155
'id > %d ORDER BY id ASC LIMIT %d',
5256
$this->cursor,

0 commit comments

Comments
 (0)