mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-13 10:22:42 +01:00
42c0f060d5
Summary: Ref T2852. I want to model Asana integration as a response to feed events. Currently, we queue one feed event for each HTTP hook. Instead, always queue one feed event and then have it queue any necessary followup events (now, http hooks; soon, asana). Add a script to make it easy to reproducibly fire feed event publishing. Test Plan: Republished a feed event and verified it hit configured HTTP hooks correctly. $ ./bin/feed republish 5765774156541908292 --trace >>> [2] <connect> phabricator2_feed <<< [2] <connect> 1,660 us >>> [3] <query> SELECT story.* FROM `feed_storydata` story JOIN `feed_storyreference` ref ON ref.chronologicalKey = story.chronologicalKey WHERE (ref.chronologicalKey IN (5765774156541908292)) GROUP BY story.chronologicalKey ORDER BY story.chronologicalKey DESC <<< [3] <query> 595 us >>> [4] <connect> phabricator2_differential <<< [4] <connect> 760 us >>> [5] <query> SELECT * FROM `differential_revision` WHERE phid IN ('PHID-DREV-ywqmrj5zgkdloqh5p3c5') <<< [5] <query> 478 us >>> [6] <query> SELECT * FROM `differential_revision` WHERE phid IN ('PHID-DREV-ywqmrj5zgkdloqh5p3c5') <<< [6] <query> 449 us >>> [7] <connect> phabricator2_user <<< [7] <connect> 1,062 us >>> [8] <query> SELECT * FROM `user` WHERE phid in ('PHID-USER-lqiz3yd7wmk64ejugvov') <<< [8] <query> 540 us >>> [9] <connect> phabricator2_file <<< [9] <connect> 951 us >>> [10] <query> SELECT * FROM `file` WHERE phid IN ('PHID-FILE-gq6dlsysvxbn3dgwvky7') <<< [10] <query> 498 us >>> [11] <query> SELECT * FROM `user_status` WHERE userPHID IN ('PHID-USER-lqiz3yd7wmk64ejugvov') AND UNIX_TIMESTAMP() BETWEEN dateFrom AND dateTo <<< [11] <query> 507 us Republishing story... >>> [12] <query> SELECT story.* FROM `feed_storydata` story JOIN `feed_storyreference` ref ON ref.chronologicalKey = story.chronologicalKey WHERE (ref.chronologicalKey IN (5765774156541908292)) GROUP BY story.chronologicalKey ORDER BY story.chronologicalKey DESC <<< [12] <query> 685 us >>> [13] <query> SELECT * FROM `differential_revision` WHERE phid IN ('PHID-DREV-ywqmrj5zgkdloqh5p3c5') <<< [13] <query> 489 us >>> [14] <query> SELECT * FROM `differential_revision` WHERE phid IN ('PHID-DREV-ywqmrj5zgkdloqh5p3c5') <<< [14] <query> 512 us >>> [15] <query> SELECT * FROM `user` WHERE phid in ('PHID-USER-lqiz3yd7wmk64ejugvov') <<< [15] <query> 601 us >>> [16] <query> SELECT * FROM `file` WHERE phid IN ('PHID-FILE-gq6dlsysvxbn3dgwvky7') <<< [16] <query> 405 us >>> [17] <query> SELECT * FROM `user_status` WHERE userPHID IN ('PHID-USER-lqiz3yd7wmk64ejugvov') AND UNIX_TIMESTAMP() BETWEEN dateFrom AND dateTo <<< [17] <query> 551 us >>> [18] <query> SELECT story.* FROM `feed_storydata` story JOIN `feed_storyreference` ref ON ref.chronologicalKey = story.chronologicalKey WHERE (ref.chronologicalKey IN (5765774156541908292)) GROUP BY story.chronologicalKey ORDER BY story.chronologicalKey DESC <<< [18] <query> 507 us >>> [19] <query> SELECT * FROM `differential_revision` WHERE phid IN ('PHID-DREV-ywqmrj5zgkdloqh5p3c5') <<< [19] <query> 428 us >>> [20] <query> SELECT * FROM `differential_revision` WHERE phid IN ('PHID-DREV-ywqmrj5zgkdloqh5p3c5') <<< [20] <query> 419 us >>> [21] <query> SELECT * FROM `user` WHERE phid in ('PHID-USER-lqiz3yd7wmk64ejugvov') <<< [21] <query> 591 us >>> [22] <query> SELECT * FROM `file` WHERE phid IN ('PHID-FILE-gq6dlsysvxbn3dgwvky7') <<< [22] <query> 406 us >>> [23] <query> SELECT * FROM `user_status` WHERE userPHID IN ('PHID-USER-lqiz3yd7wmk64ejugvov') AND UNIX_TIMESTAMP() BETWEEN dateFrom AND dateTo <<< [23] <query> 593 us >>> [24] <http> http://127.0.0.1/derp/ <<< [24] <http> 746,157 us [2013-06-24 20:23:26] EXCEPTION: (HTTPFutureResponseStatusHTTP) [HTTP/500] Internal Server Error Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2852 Differential Revision: https://secure.phabricator.com/D6291
107 lines
2.9 KiB
PHP
107 lines
2.9 KiB
PHP
<?php
|
|
|
|
final class PhabricatorFeedQuery
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
private $filterPHIDs;
|
|
private $chronologicalKeys;
|
|
|
|
public function setFilterPHIDs(array $phids) {
|
|
$this->filterPHIDs = $phids;
|
|
return $this;
|
|
}
|
|
|
|
public function withChronologicalKeys(array $keys) {
|
|
$this->chronologicalKeys = $keys;
|
|
return $this;
|
|
}
|
|
|
|
protected function loadPage() {
|
|
|
|
$story_table = new PhabricatorFeedStoryData();
|
|
$conn = $story_table->establishConnection('r');
|
|
|
|
$data = queryfx_all(
|
|
$conn,
|
|
'SELECT story.* FROM %T story %Q %Q %Q %Q %Q',
|
|
$story_table->getTableName(),
|
|
$this->buildJoinClause($conn),
|
|
$this->buildWhereClause($conn),
|
|
$this->buildGroupClause($conn),
|
|
$this->buildOrderClause($conn),
|
|
$this->buildLimitClause($conn));
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function willFilterPage(array $data) {
|
|
return PhabricatorFeedStory::loadAllFromRows($data, $this->getViewer());
|
|
}
|
|
|
|
private function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
|
// NOTE: We perform this join unconditionally (even if we have no filter
|
|
// PHIDs) to omit rows which have no story references. These story data
|
|
// rows are notifications or realtime alerts.
|
|
|
|
$ref_table = new PhabricatorFeedStoryReference();
|
|
return qsprintf(
|
|
$conn_r,
|
|
'JOIN %T ref ON ref.chronologicalKey = story.chronologicalKey',
|
|
$ref_table->getTableName());
|
|
}
|
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
$where = array();
|
|
|
|
if ($this->filterPHIDs) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'ref.objectPHID IN (%Ls)',
|
|
$this->filterPHIDs);
|
|
}
|
|
|
|
if ($this->chronologicalKeys) {
|
|
// NOTE: We want to use integers in the query so we can take advantage
|
|
// of keys, but can't use %d on 32-bit systems. Make sure all the keys
|
|
// are integers and then format them raw.
|
|
|
|
$keys = $this->chronologicalKeys;
|
|
foreach ($keys as $key) {
|
|
if (!ctype_digit($key)) {
|
|
throw new Exception("Key '{$key}' is not a valid chronological key!");
|
|
}
|
|
}
|
|
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'ref.chronologicalKey IN (%Q)',
|
|
implode(', ', $keys));
|
|
}
|
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
return $this->formatWhereClause($where);
|
|
}
|
|
|
|
private function buildGroupClause(AphrontDatabaseConnection $conn_r) {
|
|
return qsprintf(
|
|
$conn_r,
|
|
'GROUP BY '.($this->filterPHIDs
|
|
? 'ref.chronologicalKey'
|
|
: 'story.chronologicalKey'));
|
|
}
|
|
|
|
protected function getPagingColumn() {
|
|
return ($this->filterPHIDs
|
|
? 'ref.chronologicalKey'
|
|
: 'story.chronologicalKey');
|
|
}
|
|
|
|
protected function getPagingValue($item) {
|
|
if ($item instanceof PhabricatorFeedStory) {
|
|
return $item->getChronologicalKey();
|
|
}
|
|
return $item['chronologicalKey'];
|
|
}
|
|
|
|
}
|