1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 09:20:58 +01:00

Restricting query to return the displayed range

Summary: Ref T4393, Refactoring calendar query logic to only return at most what the query dates have specified

Test Plan: Query Calendar events for range May 1 - indefinite in month view, see events, scroll back to April, events should be absent, because April is out of range.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T4393

Differential Revision: https://secure.phabricator.com/D12728
This commit is contained in:
lkassianik 2015-05-05 16:04:00 -07:00
parent 7c063c7d63
commit 88ef32f61c

View file

@ -52,35 +52,35 @@ final class PhabricatorCalendarEventSearchEngine
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new PhabricatorCalendarEventQuery()); $query = id(new PhabricatorCalendarEventQuery());
$viewer = $this->requireViewer(); $viewer = $this->requireViewer();
$timezone = new DateTimeZone($viewer->getTimezoneIdentifier());
$min_range = $this->getDateFrom($saved)->getEpoch(); $min_range = $this->getDateFrom($saved)->getEpoch();
$max_range = $this->getDateTo($saved)->getEpoch(); $max_range = $this->getDateTo($saved)->getEpoch();
if ($saved->getParameter('display') == 'month') { if ($saved->getParameter('display') == 'month' ||
list($start_year, $start_month) = $saved->getParameter('display') == 'day') {
list($start_year, $start_month, $start_day) =
$this->getDisplayYearAndMonthAndDay($saved); $this->getDisplayYearAndMonthAndDay($saved);
$start_day = 1;
$end_year = ($start_month == 12) ? $start_year + 1 : $start_year; $start_day = new DateTime(
$end_month = ($start_month == 12) ? 1 : $start_month + 1; "{$start_year}-{$start_month}-{$start_day}",
$end_day = 1; $timezone);
$next = clone $start_day;
$calendar_start = AphrontFormDateControlValue::newFromParts( if ($saved->getParameter('display') == 'month') {
$viewer, $next->modify('+1 month');
$start_year, } else if ($saved->getParameter('display') == 'day') {
$start_month, $next->modify('+1 day');
$start_day)->getEpoch();
$calendar_end = AphrontFormDateControlValue::newFromParts(
$viewer,
$end_year,
$end_month,
$end_day)->getEpoch();
if (!$min_range || ($min_range < $calendar_start)) {
$min_range = $calendar_start;
} }
if (!$max_range || ($max_range > $calendar_end)) {
$max_range = $calendar_end; $display_start = $start_day->format('U');
$display_end = $next->format('U');
if (!$min_range || ($min_range < $display_start)) {
$min_range = $display_start;
}
if (!$max_range || ($max_range > $display_end)) {
$max_range = $display_end;
} }
} }