This repository has been archived by the owner on Sep 20, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a builder that constructs a MultipleBatchingFetcher
This is to not force users to have to construct a fetcher for each type of entity themselves
- Loading branch information
1 parent
c584358
commit 5cb2d6b
Showing
5 changed files
with
60 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Wikibase\EntityStore; | ||
|
||
use BatchingIterator\Fetchers\MultipleBatchingFetcher; | ||
use Wikibase\DataModel\Entity\EntityId; | ||
use Wikibase\EntityPerPage; | ||
|
||
/** | ||
* @since 0.2 | ||
* @licence GNU GPL v2+ | ||
* @author Jeroen De Dauw < jeroendedauw@gmail.com > | ||
*/ | ||
class BatchingEntityIdFetcherBuilder { | ||
|
||
private $entityPerPageTable; | ||
private $previousId; | ||
|
||
private $fetchers = array(); | ||
|
||
public function __construct( EntityPerPage $entityPerPageTable, EntityId $previousId = null ) { | ||
$this->entityPerPageTable = $entityPerPageTable; | ||
$this->previousId = $previousId; | ||
|
||
$this->addFetcherForEntityType( 'item' ); | ||
$this->addFetcherForEntityType( 'property' ); | ||
} | ||
|
||
private function addFetcherForEntityType( $entityType ) { | ||
$this->fetchers[] = new TypedEntityIdFetcher( | ||
$this->entityPerPageTable, | ||
$entityType, | ||
$this->getPreviousIdForEntityType( $entityType ) | ||
); | ||
} | ||
|
||
private function getPreviousIdForEntityType( $entityType ) { | ||
if ( $this->previousId !== null && $this->previousId->getEntityType() === $entityType ) { | ||
return $this->previousId; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function getFetcher() { | ||
return new MultipleBatchingFetcher( $this->fetchers ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters