Skip to content

Commit

Permalink
Merge pull request #93 from talis/only-ensure-on-current-repset
Browse files Browse the repository at this point in the history
90% - Fixes #92
  • Loading branch information
Chris Clarke committed Aug 28, 2015
2 parents 824a226 + 7b3b973 commit ecbcd99
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/mongo/delegates/Tables.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,13 @@ public function generateTableRows($tableType,$resource=null,$context=null,$queue
// ensure any custom view indexes
foreach (Config::getInstance()->getTableSpecifications($this->storeName) as $tSpec)
{
if (isset($tSpec['ensureIndexes']))
if (isset($tSpec['ensureIndexes']) && $tSpec['to_data_source'] == $tableSpec['to_data_source']) // only ensure table_rows indexes for the data source that matches the table spec we're generating
{
foreach ($tSpec['ensureIndexes'] as $ensureIndex)
{
$collection->ensureIndex(
$ensureIndex,
array(
'background'=>1
)
$this->ensureIndex(
$collection,
$ensureIndex
);
}
}
Expand Down Expand Up @@ -1426,6 +1424,21 @@ protected function checkIfTypeShouldTriggerOperation($rdfType, array $validTypes
return false;
}

/**
* Ensure $indexToEnsure on the given mongo $collection
* @param array $collection
* @param \MongoCollection $indexToEnsure
*/
protected function ensureIndex(\MongoCollection $collection,array $indexToEnsure)
{
$collection->ensureIndex(
$indexToEnsure,
array(
'background'=>1
)
);

}
/**
* Apply a regex to the RDF property value defined in $value
* @param $regex
Expand Down
27 changes: 27 additions & 0 deletions test/unit/mongo/MongoTripodTablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,33 @@ public function testJoinLinkValueIsForJoinedResource()
$this->assertEquals("http://talisaspire.com/works/4d101f63c10a6", $rows['results'][0]['workLink']);
}


/**
* Test to ensure only indexes on rs2 get ensured when table row generation happens
*/
public function testJoinLinkGenerationOnlyFiresEnsureIndexesForOwnDataSource()
{
/* @var $mockTables \Tripod\Mongo\Composites\Tables|PHPUnit_Framework_MockObject_MockObject*/
$mockTables = $this->getMock('\Tripod\Mongo\Composites\Tables',array("ensureIndex"),array($this->tripod->getStoreName(),$this->getTripodCollection($this->tripod),null));

$mockTables->expects($this->once())->method("ensureIndex"); // should only ever get called once

$mockTables->generateTableRows("t_join_link","http://somesubject");
}

/**
* Test to ensure only indexes on rs2 get ensured when table row generation happens
*/
public function testResourceGenerationOnlyFiresEnsureIndexesForOwnDataSource()
{
/* @var $mockTables \Tripod\Mongo\Composites\Tables|PHPUnit_Framework_MockObject_MockObject*/
$mockTables = $this->getMock('\Tripod\Mongo\Composites\Tables',array("ensureIndex"),array($this->tripod->getStoreName(),$this->getTripodCollection($this->tripod),null));

$mockTables->expects($this->exactly(3))->method("ensureIndex"); // should only ever get called twice

$mockTables->generateTableRows("t_resource","http://somesubject");
}

/**
* Test to ensure that impact index contains joined ids for resources that do not yet exist in the database (i.e.
* allow open world model)
Expand Down
5 changes: 5 additions & 0 deletions test/unit/mongo/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,11 @@
"type": "bibo:Document",
"from": "CBD_testing",
"to_data_source": "rs2",
"ensureIndexes" : [
{
"value.bookLink": 1
}
],
"fields": [
{
"fieldName": "bookLink",
Expand Down

0 comments on commit ecbcd99

Please sign in to comment.