/** * Returns the revision with the given id. * * @param UUID $uuid * @return AbstractRevision|null null if there is no such revision */ public function getRevision(UUID $uuid) { // check if fetching last already res if (isset($this->revisions[$uuid->getAlphadecimal()])) { return $this->revisions[$uuid->getAlphadecimal()]; } /* * The strategy here is to avoid having to call getAllRevisions(), which * is most likely to have to load (fresh) data that is not yet in * LocalBufferedCache's internal cache. * To do so, we'll build the $this->revisions array by hand. Starting at * the most recent revision and going up 1 revision at a time, checking * if it is already in LocalBufferedCache's cache. * If, however, we can't find the requested revisions (or one of the * revisions on our way to the requested revision) in the internal cache * of LocalBufferedCache, we'll just bail and load all revisions after * all: if we do have to fetch data, might as well do it all in 1 go! */ while (!$this->loaded()) { // fetch current oldest revision $oldest = $this->getOldestLoaded(); // fetch that one's preceding revision id $previousId = $oldest->getPrevRevisionId(); // check if it's in local storage already if ($previousId && $this->getStorage()->got($previousId)) { $revision = $this->getStorage()->get($previousId); // add this revision to revisions array $this->revisions[$previousId->getAlphadecimal()] = $revision; // stop iterating if we've found the one we wanted if ($uuid->equals($previousId)) { break; } } else { // revision not found in local storage: load all revisions $this->getAllRevisions(); break; } } if (!isset($this->revisions[$uuid->getAlphadecimal()])) { return null; } return $this->revisions[$uuid->getAlphadecimal()]; }