[ratings/search] remove implicit 'rating:*' from image counting process, hopefully fixes #991
This commit is contained in:
parent
c79751007c
commit
77e88f6f54
2 changed files with 24 additions and 3 deletions
|
@ -172,9 +172,6 @@ class Search
|
|||
$cache_key = "image-count:" . md5(Tag::implode($tags));
|
||||
$total = $cache->get($cache_key);
|
||||
if (is_null($total)) {
|
||||
if (Extension::is_enabled(RatingsInfo::KEY)) {
|
||||
$tags[] = "rating:*";
|
||||
}
|
||||
[$tag_conditions, $img_conditions, $order] = self::terms_to_conditions($tags);
|
||||
$querylet = self::build_search_querylet($tag_conditions, $img_conditions, $order);
|
||||
$total = (int)$database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables);
|
||||
|
|
|
@ -77,6 +77,30 @@ class RatingsTest extends ShimmiePHPUnitTestCase
|
|||
$this->assertEquals($image_s->get_next(), null);
|
||||
}
|
||||
|
||||
public function testCountImages(): void
|
||||
{
|
||||
global $config, $user_config;
|
||||
|
||||
$this->log_in_as_user();
|
||||
|
||||
$image_id_s = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
|
||||
$image_s = Image::by_id($image_id_s);
|
||||
send_event(new RatingSetEvent($image_s, "s"));
|
||||
$image_id_q = $this->post_image("tests/favicon.png", "favicon");
|
||||
$image_q = Image::by_id($image_id_q);
|
||||
send_event(new RatingSetEvent($image_q, "q"));
|
||||
$image_id_e = $this->post_image("tests/bedroom_workshop.jpg", "bedroom");
|
||||
$image_e = Image::by_id($image_id_e);
|
||||
send_event(new RatingSetEvent($image_e, "e"));
|
||||
|
||||
$config->set_array("ext_rating_user_privs", ["s", "q"]);
|
||||
$user_config->set_array(RatingsConfig::USER_DEFAULTS, ["s"]);
|
||||
|
||||
$this->assertEquals(1, Search::count_images(["rating=s"]), "UserClass has access to safe, show safe");
|
||||
$this->assertEquals(2, Search::count_images(["rating=*"]), "UserClass has access to s/q - if user asks for everything, show those two but hide e");
|
||||
$this->assertEquals(1, Search::count_images(), "If search doesn't specify anything, check the user defaults");
|
||||
}
|
||||
|
||||
// reset the user config to defaults at the end of every test so
|
||||
// that it doesn't mess with other unrelated tests
|
||||
public function tearDown(): void
|
||||
|
|
Reference in a new issue