Skip to content

Commit

Permalink
Merge pull request #1522 from SemanticMediaWiki/lookup
Browse files Browse the repository at this point in the history
Use RequestOptions::getHash, refs #1151
  • Loading branch information
mwjames committed Apr 21, 2016
2 parents 94751ca + 5c07ac9 commit f6d7939
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/SQLStore/Lookup/CachedListLookup.php
Expand Up @@ -12,7 +12,7 @@
*/
class CachedListLookup implements ListLookup {

const VERSION = '0.1';
const VERSION = '0.2';

/**
* @var ListLookup
Expand Down Expand Up @@ -193,7 +193,7 @@ private function getCacheKey( $id ) {

return array(
$this->cachePrefix . md5( $id . self::VERSION ),
$this->cachePrefix . md5( $optionsKey . self::VERSION )
$this->cachePrefix . md5( $id . $optionsKey . self::VERSION )
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/SQLStore/Lookup/PropertyUsageListLookup.php
Expand Up @@ -86,7 +86,7 @@ public function getTimestamp() {
* @return string
*/
public function getLookupIdentifier() {
return 'smwgPropertiesCache#' . json_encode( (array)$this->requestOptions );
return __METHOD__ . '#' . ( $this->requestOptions !== null ? $this->requestOptions->getHash() : '' );
}

private function doQueryPropertyTable() {
Expand Down
2 changes: 1 addition & 1 deletion src/SQLStore/Lookup/UndeclaredPropertyListLookup.php
Expand Up @@ -92,7 +92,7 @@ public function getTimestamp() {
* @return string
*/
public function getLookupIdentifier() {
return __METHOD__. '#' . json_encode( (array)$this->requestOptions );
return __METHOD__ . '#' . ( $this->requestOptions !== null ? $this->requestOptions->getHash() : '' );
}

private function selectPropertiesFromTable( $propertyTable ) {
Expand Down
2 changes: 1 addition & 1 deletion src/SQLStore/Lookup/UnusedPropertyListLookup.php
Expand Up @@ -86,7 +86,7 @@ public function getTimestamp() {
* @return string
*/
public function getLookupIdentifier() {
return __METHOD__ . '#' . json_encode( (array)$this->requestOptions );
return __METHOD__ . '#' . ( $this->requestOptions !== null ? $this->requestOptions->getHash() : '' );
}

private function selectPropertiesFromTable() {
Expand Down
21 changes: 7 additions & 14 deletions tests/phpunit/Unit/SQLStore/Lookup/PropertyUsageListLookupTest.php
Expand Up @@ -4,6 +4,7 @@

use SMW\DIProperty;
use SMW\SQLStore\Lookup\PropertyUsageListLookup;
use SMW\RequestOptions;

/**
* @covers \SMW\SQLStore\Lookup\PropertyUsageListLookup
Expand Down Expand Up @@ -61,37 +62,29 @@ public function testListLookupInterfaceMethodAccess() {
);

$this->assertContains(
'smwgPropertiesCache',
'PropertyUsageListLookup',
$instance->getLookupIdentifier()
);
}

public function testLookupIdentifierChangedByRequestOptions() {

$requestOptions = new RequestOptions();

$instance = new PropertyUsageListLookup(
$this->store,
$this->propertyStatisticsStore,
$this->requestOptions
$requestOptions
);

$lookupIdentifier = $instance->getLookupIdentifier();

$this->assertContains(
'smwgPropertiesCache',
$lookupIdentifier
);

$this->requestOptions->limit = 100;
$requestOptions->limit = 100;

$instance = new PropertyUsageListLookup(
$this->store,
$this->propertyStatisticsStore,
$this->requestOptions
);

$this->assertContains(
'smwgPropertiesCache',
$instance->getLookupIdentifier()
$requestOptions
);

$this->assertNotSame(
Expand Down
Expand Up @@ -4,6 +4,7 @@

use SMW\DIProperty;
use SMW\SQLStore\Lookup\UndeclaredPropertyListLookup;
use SMW\RequestOptions;

/**
* @covers \SMW\SQLStore\Lookup\UndeclaredPropertyListLookup
Expand Down Expand Up @@ -95,32 +96,23 @@ public function testInvalidTableIdThrowsException() {
public function testLookupIdentifierChangedByRequestOptions() {

$defaultPropertyType = '_foo';
$requestOptions = new RequestOptions();

$instance = new UndeclaredPropertyListLookup(
$this->store,
$defaultPropertyType,
$this->requestOptions
$requestOptions
);

$lookupIdentifier = $instance->getLookupIdentifier();

$this->assertContains(
'UndeclaredPropertyListLookup',
$lookupIdentifier
);

$this->requestOptions->limit = 100;
$requestOptions->limit = 100;

$instance = new UndeclaredPropertyListLookup(
$this->store,
$defaultPropertyType,
$this->requestOptions
$requestOptions
);

$this->assertContains(
'UndeclaredPropertyListLookup',
$instance->getLookupIdentifier()
);

$this->assertNotSame(
$lookupIdentifier,
Expand Down
Expand Up @@ -4,6 +4,7 @@

use SMW\DIProperty;
use SMW\SQLStore\Lookup\UnusedPropertyListLookup;
use SMW\RequestOptions;

/**
* @covers \SMW\SQLStore\Lookup\UnusedPropertyListLookup
Expand Down Expand Up @@ -68,30 +69,22 @@ public function testListLookupInterfaceMethodAccess() {

public function testLookupIdentifierChangedByRequestOptions() {

$requestOptions = new RequestOptions();

$instance = new UnusedPropertyListLookup(
$this->store,
$this->propertyStatisticsTable,
$this->requestOptions
$requestOptions
);

$lookupIdentifier = $instance->getLookupIdentifier();

$this->assertContains(
'UnusedPropertyListLookup',
$lookupIdentifier
);

$this->requestOptions->limit = 100;
$requestOptions->limit = 100;

$instance = new UnusedPropertyListLookup(
$this->store,
$this->propertyStatisticsTable,
$this->requestOptions
);

$this->assertContains(
'UnusedPropertyListLookup',
$instance->getLookupIdentifier()
$requestOptions
);

$this->assertNotSame(
Expand Down

0 comments on commit f6d7939

Please sign in to comment.