mirror of
https://codeberg.org/vlw/vlw.se.git
synced 2025-09-13 21:13:40 +02:00
feat: add endpoint for updating runtime stats (#35)
Replacing all GET update params with a single update endpoint that calls POST on all endpoints that trigger runtime stats Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/35
This commit is contained in:
parent
a6c74f5c4f
commit
fef10a8ea8
6 changed files with 30 additions and 47 deletions
|
@ -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
|
||||
]);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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]) {
|
||||
|
|
26
endpoints/update/GET.php
Normal file
26
endpoints/update/GET.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path, Call};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\API\Endpoints;
|
||||
|
||||
require_once Path::root("src/API/Endpoints.php");
|
||||
|
||||
class GET_Update {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->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();
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
@ -38,4 +31,3 @@
|
|||
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";
|
|
@ -27,6 +27,7 @@ INSERT INTO `endpoints` (`id`, `active`) VALUES
|
|||
('notes', 1),
|
||||
('playground/coffee', 1),
|
||||
('search', 1),
|
||||
('update', 1),
|
||||
('work', 1),
|
||||
('work/actions', 1),
|
||||
('work/tags', 1),
|
||||
|
|
Loading…
Add table
Reference in a new issue