Skip to content

Commit

Permalink
[tag_list] remove hacky caching for tag lists
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Dec 13, 2024
1 parent 84692b9 commit cb4ff59
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 43 deletions.
2 changes: 1 addition & 1 deletion ext/comment/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function onPageRequest(PageRequestEvent $event): void
if ($event->page_matches("comment/list", paged: true)) {
$threads_per_page = 10;

$speed_hax = (Extension::is_enabled(SpeedHaxInfo::KEY) && $config->get_bool(SpeedHaxConfig::CACHE_TAG_LISTS));
$speed_hax = (Extension::is_enabled(SpeedHaxInfo::KEY) && $config->get_bool(SpeedHaxConfig::RECENT_COMMENTS));
$where = $speed_hax ? "WHERE posted > now() - interval '24 hours'" : "";

$total_pages = cache_get_or_set("comment_pages", fn () => (int)ceil($database->get_one("
Expand Down
3 changes: 0 additions & 3 deletions ext/speed_hax/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ abstract class SpeedHaxConfig
{
public const NO_AUTO_DB_UPGRADE = "speed_hax_no_auto_db_upgrade";
public const CACHE_EVENT_LISTENERS = "speed_hax_cache_listeners";
public const CACHE_TAG_LISTS = "speed_hax_cache_tag_lists";
public const PURGE_COOKIE = "speed_hax_purge_cookie";
public const RECENT_COMMENTS = "speed_hax_recent_comments";
public const BIG_SEARCH = "speed_hax_big_search";
Expand All @@ -26,7 +25,6 @@ public function onInitExt(InitExtEvent $event): void

$config->set_default_bool(SpeedHaxConfig::NO_AUTO_DB_UPGRADE, false);
$config->set_default_bool(SpeedHaxConfig::CACHE_EVENT_LISTENERS, false);
$config->set_default_bool(SpeedHaxConfig::CACHE_TAG_LISTS, false);
$config->set_default_bool(SpeedHaxConfig::PURGE_COOKIE, false);
$config->set_default_bool(SpeedHaxConfig::RECENT_COMMENTS, false);
$config->set_default_int(SpeedHaxConfig::BIG_SEARCH, 0);
Expand All @@ -42,7 +40,6 @@ public function onSetupBuilding(SetupBuildingEvent $event): void
$sb->start_table();
$sb->add_bool_option(SpeedHaxConfig::NO_AUTO_DB_UPGRADE, "Don't auto-upgrade database: ", false);
$sb->add_bool_option(SpeedHaxConfig::CACHE_EVENT_LISTENERS, "<br>Cache event listeners: ", false);
$sb->add_bool_option(SpeedHaxConfig::CACHE_TAG_LISTS, "<br>Cache tag lists: ", false);
$sb->add_bool_option(SpeedHaxConfig::PURGE_COOKIE, "<br>Purge cookie on logout: ", false);
$sb->add_bool_option(SpeedHaxConfig::RECENT_COMMENTS, "<br>List only recent comments: ", false);
$sb->add_int_option(SpeedHaxConfig::BIG_SEARCH, "<br>Anonymous search tag limit: ", false);
Expand Down
39 changes: 0 additions & 39 deletions ext/tag_list/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,6 @@ private function build_tag_map(string $starts_with, int $tags_min): string
{
global $config, $database;

// check if we have a cached version
$cache_key = warehouse_path(
"cache/tag_cloud",
md5("tc" . $tags_min . $starts_with . VERSION)
);
if (file_exists($cache_key)) {
return \Safe\file_get_contents($cache_key);
}

$tag_data = $database->get_all("
SELECT
tag,
Expand Down Expand Up @@ -257,26 +248,13 @@ private function build_tag_map(string $starts_with, int $tags_min): string
$html .= "&nbsp;<a style='font-size: {$size}em' href='$link'>$h_tag_no_underscores</a>&nbsp;\n";
}

if (Extension::is_enabled(SpeedHaxInfo::KEY) && $config->get_bool(SpeedHaxConfig::CACHE_TAG_LISTS)) {
file_put_contents($cache_key, $html);
}

return $html;
}

private function build_tag_alphabetic(string $starts_with, int $tags_min): string
{
global $config, $database;

// check if we have a cached version
$cache_key = warehouse_path(
"cache/tag_alpha",
md5("ta" . $tags_min . $starts_with . VERSION)
);
if (file_exists($cache_key)) {
return \Safe\file_get_contents($cache_key);
}

$tag_data = $database->get_pairs("
SELECT tag, count
FROM tags
Expand Down Expand Up @@ -325,10 +303,6 @@ private function build_tag_alphabetic(string $starts_with, int $tags_min): strin
$html .= "<a href='$link'>$h_tag</a>\n";
}

if (Extension::is_enabled(SpeedHaxInfo::KEY) && $config->get_bool(SpeedHaxConfig::CACHE_TAG_LISTS)) {
file_put_contents($cache_key, $html);
}

return $html;
}

Expand All @@ -342,15 +316,6 @@ private function build_tag_popularity(int $tags_min): string
$tags_min = 1;
}

// check if we have a cached version
$cache_key = warehouse_path(
"cache/tag_popul",
md5("tp" . $tags_min . VERSION)
);
if (file_exists($cache_key)) {
return \Safe\file_get_contents($cache_key);
}

$tag_data = $database->get_all("
SELECT tag, count, FLOOR(LOG(10, count)) AS scaled
FROM tags
Expand All @@ -372,10 +337,6 @@ private function build_tag_popularity(int $tags_min): string
$html .= "<a href='$link'>$h_tag&nbsp;($count)</a>\n";
}

if (Extension::is_enabled(SpeedHaxInfo::KEY) && $config->get_bool(SpeedHaxConfig::CACHE_TAG_LISTS)) {
file_put_contents($cache_key, $html);
}

return $html;
}

Expand Down

0 comments on commit cb4ff59

Please sign in to comment.