Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/query/PhabricatorPeopleQuery.php
| Show First 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | protected function didFilterPage(array $users) { | ||||
| } | } | ||||
| if ($this->needAvailability) { | if ($this->needAvailability) { | ||||
| $rebuild = array(); | $rebuild = array(); | ||||
| foreach ($users as $user) { | foreach ($users as $user) { | ||||
| $cache = $user->getAvailabilityCache(); | $cache = $user->getAvailabilityCache(); | ||||
| if ($cache !== null) { | if ($cache !== null) { | ||||
| $user->attachAvailability($cache); | $user->attachAvailability($cache); | ||||
| } else { | } else { | ||||
| $rebuild[] = $user; | $rebuild[] = $user; | ||||
| } | } | ||||
aik099: Are you sure, that caching is no longer needed? | |||||
Not Done Inline ActionsAh, good call. Testing gibberish. lpriestley: Ah, good call. Testing gibberish. | |||||
| } | } | ||||
| if ($rebuild) { | if ($rebuild) { | ||||
| $this->rebuildAvailabilityCache($rebuild); | $this->rebuildAvailabilityCache($rebuild); | ||||
| } | } | ||||
| } | } | ||||
| return $users; | return $users; | ||||
| ▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | private function rebuildAvailabilityCache(array $rebuild) { | ||||
| // Limit the window we look at because far-future events are largely | // Limit the window we look at because far-future events are largely | ||||
| // irrelevant and this makes the cache cheaper to build and allows it to | // irrelevant and this makes the cache cheaper to build and allows it to | ||||
| // self-heal over time. | // self-heal over time. | ||||
| $min_range = PhabricatorTime::getNow(); | $min_range = PhabricatorTime::getNow(); | ||||
| $max_range = $min_range + phutil_units('72 hours in seconds'); | $max_range = $min_range + phutil_units('72 hours in seconds'); | ||||
| $events = id(new PhabricatorCalendarEventQuery()) | $events = id(new PhabricatorCalendarEventQuery()) | ||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
| ->setSkipApplyTimezone(true) | |||||
| ->setGenerateGhosts(true) | |||||
| ->withInvitedPHIDs(array_keys($rebuild)) | ->withInvitedPHIDs(array_keys($rebuild)) | ||||
| ->withIsCancelled(false) | ->withIsCancelled(false) | ||||
| ->withDateRange($min_range, $max_range) | ->withDateRange($min_range, $max_range) | ||||
| ->execute(); | ->execute(); | ||||
| // Group all the events by invited user. Only examine events that users | // Group all the events by invited user. Only examine events that users | ||||
| // are actually attending. | // are actually attending. | ||||
| $map = array(); | $map = array(); | ||||
| Show All 16 Lines | foreach ($rebuild as $phid => $user) { | ||||
| $events = idx($map, $phid, array()); | $events = idx($map, $phid, array()); | ||||
| $cursor = $min_range; | $cursor = $min_range; | ||||
| if ($events) { | if ($events) { | ||||
| // Find the next time when the user has no meetings. If we move forward | // Find the next time when the user has no meetings. If we move forward | ||||
| // because of an event, we check again for events after that one ends. | // because of an event, we check again for events after that one ends. | ||||
| while (true) { | while (true) { | ||||
| foreach ($events as $event) { | foreach ($events as $event) { | ||||
| $from = $event->getDateFromForCache(); | $event_for_timezone = clone $event; | ||||
| $to = $event->getDateTo(); | $event_for_timezone->applyViewerTimezone($user); | ||||
| $from = $event_for_timezone->getDateFromForCache(); | |||||
| $to = $event_for_timezone->getDateTo(); | |||||
| if (($from <= $cursor) && ($to > $cursor)) { | if (($from <= $cursor) && ($to > $cursor)) { | ||||
| $cursor = $to; | $cursor = $to; | ||||
| continue 2; | continue 2; | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| Show All 22 Lines | |||||
Are you sure, that caching is no longer needed?