@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Attempt to optimize ghost generating code.

Summary: Ref T8394, Attempt to optimize ghost generating code.

Test Plan: Open Upcoming, cancelled only, list view query. Should not hang.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T8394

Differential Revision: https://secure.phabricator.com/D13141

+26 -5
+26 -5
src/applications/calendar/query/PhabricatorCalendarEventQuery.php
··· 110 110 return $events; 111 111 } 112 112 113 - $map = array(); 114 - $instance_sequence_pairs = array(); 113 + $enforced_end = null; 115 114 116 115 foreach ($events as $key => $event) { 117 116 $sequence_start = 0; ··· 159 158 $end = $event->getRecurrenceEndDate(); 160 159 } else if ($this->rangeEnd) { 161 160 $end = $this->rangeEnd; 161 + } else if ($enforced_end) { 162 + if ($end) { 163 + $end = min($end, $enforced_end); 164 + } else { 165 + $end = $enforced_end; 166 + } 162 167 } 163 168 164 169 if ($end) { ··· 167 172 $sequence_end++; 168 173 $datetime->modify($modify_key); 169 174 $date = $datetime->format('U'); 175 + if ($sequence_end > $this->getRawResultLimit() + $sequence_start) { 176 + break; 177 + } 170 178 } 171 179 } else { 172 180 $sequence_end = $this->getRawResultLimit() + $sequence_start; ··· 175 183 $sequence_start = max(1, $sequence_start); 176 184 177 185 for ($index = $sequence_start; $index < $sequence_end; $index++) { 178 - $instance_sequence_pairs[] = array($event->getPHID(), $index); 179 186 $events[] = $event->generateNthGhost($index, $viewer); 187 + } 180 188 181 - $last_key = last_key($events); 182 - $map[$event->getPHID()][$index] = $last_key; 189 + if (count($events) >= $this->getRawResultLimit()) { 190 + $events = msort($events, 'getDateFrom'); 191 + $events = array_slice($events, 0, $this->getRawResultLimit(), true); 192 + $enforced_end = last($events)->getDateFrom(); 183 193 } 194 + } 195 + } 196 + 197 + $map = array(); 198 + $instance_sequence_pairs = array(); 199 + 200 + foreach ($events as $key => $event) { 201 + if ($event->getIsGhostEvent()) { 202 + $index = $event->getSequenceIndex(); 203 + $instance_sequence_pairs[] = array($event->getPHID(), $index); 204 + $map[$event->getPHID()][$index] = $key; 184 205 } 185 206 } 186 207