diff --git a/endpoints/about/languages/GET.php b/endpoints/about/languages/GET.php index 92e3b29..66680df 100644 --- a/endpoints/about/languages/GET.php +++ b/endpoints/about/languages/GET.php @@ -6,10 +6,8 @@ use VLW\API\Endpoints; use VLW\Database\Database; - use const VLW\FORGEJO_UPDATE_CACHE_PARAM; use VLW\Database\Tables\About\LanguagesTable; - require_once Path::root("src/Consts.php"); require_once Path::root("src/API/Endpoints.php"); require_once Path::root("src/Database/Database.php"); require_once Path::root("src/Database/Tables/About/Languages.php"); @@ -29,11 +27,7 @@ (new Rules(LanguagesTable::BYTES->value)) ->type(Type::NUMBER) ->min(1) - ->max(parent::SIZE_UINT32), - - (new Rules(FORGEJO_UPDATE_CACHE_PARAM)) - ->type(Type::BOOLEAN) - ->default(false) + ->max(parent::SIZE_UINT32) ]); $this->ruleset->validate_or_exit(); @@ -42,11 +36,6 @@ } public function main(): Response { - // Refresh the language cache if param is set - if ($_GET[FORGEJO_UPDATE_CACHE_PARAM]) { - (new Call(Endpoints::ABOUT_LANGUAGES->value))->post(); - } - return $this->list(LanguagesTable::NAME, LanguagesTable::values(), [ LanguagesTable::BYTES->value => Order::DESC ]); diff --git a/endpoints/coffee/stats/GET.php b/endpoints/coffee/stats/GET.php index 0514a0a..a9a8b9e 100644 --- a/endpoints/coffee/stats/GET.php +++ b/endpoints/coffee/stats/GET.php @@ -6,10 +6,8 @@ use VLW\API\Endpoints; use VLW\Database\Database; - use const VLW\COFFEE_STATS_UPDATE_PARAM; use VLW\Database\Tables\Coffee\StatsTable; - require_once Path::root("src/Consts.php"); require_once Path::root("src/API/Endpoints.php"); require_once Path::root("src/Database/Database.php"); require_once Path::root("src/Database/Tables/Coffee/Stats.php"); @@ -19,24 +17,12 @@ public function __construct() { $this->ruleset = new Ruleset(strict: true); - - $this->ruleset->GET([ - (new Rules(COFFEE_STATS_UPDATE_PARAM)) - ->type(Type::BOOLEAN) - ->default(false) - ]); - $this->ruleset->validate_or_exit(); parent::__construct(); } public function main(): Response { - // Freshen cache if update flag is set - if ($_GET[COFFEE_STATS_UPDATE_PARAM]) { - (new Call(Endpoints::COFFEE_STATS->value))->post(); - } - return $this->list(StatsTable::NAME, StatsTable::values()); } } \ No newline at end of file diff --git a/endpoints/search/GET.php b/endpoints/search/GET.php index b89e952..94463c2 100644 --- a/endpoints/search/GET.php +++ b/endpoints/search/GET.php @@ -6,10 +6,8 @@ use VLW\API\Endpoints; use VLW\Database\Database; - use const VLW\SEARCH_UPDATE_CACHE_PARM; use VLW\Database\Tables\Search\{SearchTable, SearchCategoryEnum}; - require_once Path::root("src/Consts.php"); require_once Path::root("src/API/Endpoints.php"); require_once Path::root("src/Database/Database.php"); require_once Path::root("src/Database/Tables/Search/Search.php"); @@ -35,11 +33,7 @@ (new Rules(SearchTable::CATEGORY->value)) ->type(Type::ENUM, SearchCategoryEnum::names()) - ->default(null), - - (new Rules(SEARCH_UPDATE_CACHE_PARM)) - ->type(Type::BOOLEAN) - ->default(false) + ->default(null) ]); $this->ruleset->validate_or_exit(); @@ -54,11 +48,6 @@ } public function main(): Response { - // Freshen cache if update flag is set - if ($_GET[SEARCH_UPDATE_CACHE_PARM]) { - (new Call(Endpoints::SEARCH->value))->post(); - } - $result = $this->db->for(SearchTable::NAME); if ($_GET[SearchTable::ID->value]) { diff --git a/endpoints/update/GET.php b/endpoints/update/GET.php new file mode 100644 index 0000000..10cf57c --- /dev/null +++ b/endpoints/update/GET.php @@ -0,0 +1,26 @@ +ruleset = new Ruleset(strict: true); + $this->ruleset->validate_or_exit(); + } + + // Update all runtime database endpoints + public function main(): Response { + (new Call(Endpoints::SEARCH->value))->post(); + (new Call(Endpoints::COFFEE_STATS->value))->post(); + (new Call(Endpoints::ABOUT_LANGUAGES->value))->post(); + + return new Response(); + } + } \ No newline at end of file diff --git a/src/Consts.php b/src/Consts.php index f954031..1189f98 100644 --- a/src/Consts.php +++ b/src/Consts.php @@ -15,7 +15,6 @@ * Constants for the search API endpoint */ const SEARCH_QUERY_MAX_LENGTH = 2048; - const SEARCH_UPDATE_CACHE_PARM = "update"; /** * # Timeline @@ -24,12 +23,6 @@ const TIMELINE_PREVIEW_LIMIT_PARAM = "limit"; const TIMELINE_PREVIEW_LIMIT_COUNT = 5; - /** - * # Coffee - * Constants related to the coffee endpoints - */ - const COFFEE_STATS_UPDATE_PARAM = "update"; - /** * # Forgejo * Constants related to the fetching and caching of real-time prog. language use on Forgejo @@ -37,5 +30,4 @@ const FORGEJO_HREF = "https://git.vlw.se/explore/repos?q=&sort=recentupdate&language="; const FORGEJO_ENDPOINT_USER = "/api/v1/users/%s"; const FORGEJO_ENDPOINT_SEARCH = "/api/v1/repos/search?uid=%s"; - const FORGEJO_SI_BYTE_MULTIPLE = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; - const FORGEJO_UPDATE_CACHE_PARAM = "update"; \ No newline at end of file + const FORGEJO_SI_BYTE_MULTIPLE = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; \ No newline at end of file