/** * @param array $cached * @param array $keyToQuery * @return ResultDuplicator */ public function getResultDuplicator(array $cached, array $keyToQuery) { $results = $this->inner->expandCacheResult($cached, $keyToQuery); // Allows us to flatten $results into a single $query array, then // rebuild final return value in same structure and order as $results. $duplicator = new ResultDuplicator($this->shallow->getPrimaryKeyColumns(), 2); foreach ($results as $i => $rows) { foreach ($rows as $j => $row) { $duplicator->add($row, array($i, $j)); } } return $duplicator; }
protected function findMostRecent(array $queries) { // SELECT MAX( rev_id ) AS rev_id // FROM flow_tree_revision // WHERE rev_type= 'post' AND rev_type_id IN (...) // GROUP BY rev_type_id $duplicator = new ResultDuplicator(array('rev_type_id'), 1); foreach ($queries as $idx => $query) { $query = UUID::convertUUIDs((array) $query, 'alphadecimal'); $duplicator->add($query, $idx); } $dbr = $this->dbFactory->getDB(DB_MASTER); $res = $dbr->select(array('flow_revision'), array('rev_id' => "MAX( 'rev_id' )"), array('rev_type' => $this->getRevType()) + $this->preprocessSqlArray($this->buildCompositeInCondition($dbr, $duplicator->getUniqueQueries())), __METHOD__, array('GROUP BY' => 'rev_type_id')); if (!$res) { // TODO: dont fail, but dont end up caching bad result either throw new DataModelException('query failure', 'process-data'); } $revisionIds = array(); foreach ($res as $row) { $revisionIds[] = $row->rev_id; } // Due to the grouping and max, we cant reliably get a full // columns info in the above query, forcing the join below // rather than just querying flow_revision. return $this->findRevIdReal($duplicator, $revisionIds); }