2011-03-24 21:49:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
Remove massive "rule applied" query
Summary:
Herald rules may be marked as "one-time". We track this by writing a row with
<ruleID, phid> when we apply a rule.
However, the current test for rule application involves loading every <ruleID,
*> pair. We also always write this row even for rules which are not one-time, so
if there are 100 rules, we'll load 1,000,000 rows after processing 10,000
objects.
Instead, load only the <phid, *> pairs, which are guaranteed to be bounded to at
most the number of rules.
I'll follow up with a diff that causes us to write rows only for one-time rules,
and deletes all historic rows which are not associated with one-time rules.
Test Plan:
Grepped for callsites to loadAllByContentTypeWithFullData(). Ran
rules in test console.
Reviewers: nh, btrahan, jungejason
Reviewed By: nh
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1483
2012-01-25 04:03:30 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-03-24 21:49:21 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class HeraldTestConsoleController extends HeraldController {
|
|
|
|
|
2011-12-16 22:29:32 +01:00
|
|
|
public function getFilter() {
|
|
|
|
return 'test';
|
|
|
|
}
|
|
|
|
|
2011-03-24 21:49:21 +01:00
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$object_name = trim($request->getStr('object_name'));
|
|
|
|
|
|
|
|
$e_name = true;
|
|
|
|
$errors = array();
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
if (!$object_name) {
|
|
|
|
$e_name = 'Required';
|
|
|
|
$errors[] = 'An object name is required.';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
$matches = null;
|
|
|
|
$object = null;
|
|
|
|
if (preg_match('/^D(\d+)$/', $object_name, $matches)) {
|
|
|
|
$object = id(new DifferentialRevision())->load($matches[1]);
|
|
|
|
if (!$object) {
|
|
|
|
$e_name = 'Invalid';
|
|
|
|
$errors[] = 'No Differential Revision with that ID exists.';
|
|
|
|
}
|
|
|
|
} else if (preg_match('/^r([A-Z]+)(\w+)$/', $object_name, $matches)) {
|
|
|
|
$repo = id(new PhabricatorRepository())->loadOneWhere(
|
|
|
|
'callsign = %s',
|
|
|
|
$matches[1]);
|
|
|
|
if (!$repo) {
|
|
|
|
$e_name = 'Invalid';
|
|
|
|
$errors[] = 'There is no repository with the callsign '.
|
|
|
|
$matches[1].'.';
|
|
|
|
}
|
|
|
|
$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
|
|
|
|
'repositoryID = %d AND commitIdentifier = %s',
|
|
|
|
$repo->getID(),
|
|
|
|
$matches[2]);
|
|
|
|
if (!$commit) {
|
|
|
|
$e_name = 'Invalid';
|
|
|
|
$errors[] = 'There is no commit with that identifier.';
|
|
|
|
}
|
2011-04-04 08:23:36 +02:00
|
|
|
$object = $commit;
|
2011-03-24 21:49:21 +01:00
|
|
|
} else {
|
|
|
|
$e_name = 'Invalid';
|
|
|
|
$errors[] = 'This object name is not recognized.';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
if ($object instanceof DifferentialRevision) {
|
2011-04-06 05:49:31 +02:00
|
|
|
$adapter = new HeraldDifferentialRevisionAdapter(
|
|
|
|
$object,
|
|
|
|
$object->loadActiveDiff());
|
2011-03-24 21:49:21 +01:00
|
|
|
} else if ($object instanceof PhabricatorRepositoryCommit) {
|
2011-04-04 08:23:36 +02:00
|
|
|
$data = id(new PhabricatorRepositoryCommitData())->loadOneWhere(
|
|
|
|
'commitID = %d',
|
|
|
|
$object->getID());
|
|
|
|
$adapter = new HeraldCommitAdapter(
|
|
|
|
$repo,
|
|
|
|
$object,
|
|
|
|
$data);
|
2011-03-24 21:49:21 +01:00
|
|
|
} else {
|
|
|
|
throw new Exception("Can not build adapter for object!");
|
|
|
|
}
|
|
|
|
|
|
|
|
$rules = HeraldRule::loadAllByContentTypeWithFullData(
|
Remove massive "rule applied" query
Summary:
Herald rules may be marked as "one-time". We track this by writing a row with
<ruleID, phid> when we apply a rule.
However, the current test for rule application involves loading every <ruleID,
*> pair. We also always write this row even for rules which are not one-time, so
if there are 100 rules, we'll load 1,000,000 rows after processing 10,000
objects.
Instead, load only the <phid, *> pairs, which are guaranteed to be bounded to at
most the number of rules.
I'll follow up with a diff that causes us to write rows only for one-time rules,
and deletes all historic rows which are not associated with one-time rules.
Test Plan:
Grepped for callsites to loadAllByContentTypeWithFullData(). Ran
rules in test console.
Reviewers: nh, btrahan, jungejason
Reviewed By: nh
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1483
2012-01-25 04:03:30 +01:00
|
|
|
$adapter->getHeraldTypeName(),
|
|
|
|
$object->getPHID());
|
2011-03-24 21:49:21 +01:00
|
|
|
|
|
|
|
$engine = new HeraldEngine();
|
|
|
|
$effects = $engine->applyRules($rules, $adapter);
|
|
|
|
|
|
|
|
$dry_run = new HeraldDryRunAdapter();
|
|
|
|
$engine->applyEffects($effects, $dry_run);
|
|
|
|
|
|
|
|
$xscript = $engine->getTranscript();
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('/herald/transcript/'.$xscript->getID().'/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($errors) {
|
|
|
|
$error_view = new AphrontErrorView();
|
|
|
|
$error_view->setTitle('Form Errors');
|
|
|
|
$error_view->setErrors($errors);
|
|
|
|
} else {
|
|
|
|
$error_view = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($user)
|
|
|
|
->appendChild(
|
|
|
|
'<p class="aphront-form-instructions">Enter an object to test rules '.
|
|
|
|
'for, like a Diffusion commit (e.g., <tt>rX123</tt>) or a '.
|
|
|
|
'Differential revision (e.g., <tt>D123</tt>). You will be shown the '.
|
|
|
|
'results of a dry run on the object.</p>')
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel('Object Name')
|
|
|
|
->setName('object_name')
|
|
|
|
->setError($e_name)
|
|
|
|
->setValue($object_name))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue('Test Rules'));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Test Herald Rules');
|
2011-12-16 22:29:32 +01:00
|
|
|
$panel->setWidth(AphrontPanelView::WIDTH_FULL);
|
2011-03-24 21:49:21 +01:00
|
|
|
$panel->appendChild($form);
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
array(
|
|
|
|
$error_view,
|
|
|
|
$panel,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => 'Test Console',
|
|
|
|
'tab' => 'test',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|