Fast fetch mode flag

dev
gravel 1 year ago
parent 160a924dd0
commit 25edfdb2ce
Signed by: gravel
GPG Key ID: C0538F3C906B308F

@ -10,6 +10,8 @@
// Not required
include_once "$LANGUAGES_ROOT/language_flags.php";
$FAST_FETCH_MODE = false;
/**
* Fetch online Communities and write the resulting data to disk.
* Communities are fetched as follows:
@ -22,14 +24,18 @@
* 6. De-dupe servers based on pubkey
*/
function main() {
global $LOGGING_VERBOSITY;
global $LOGGING_VERBOSITY, $FAST_FETCH_MODE;
// Read the -v|--verbose option increasing logging verbosity to debug.
$options = getopt("v", ["verbose"]);
$options = getopt("v", ["verbose", "fast"]);
if (isset($options["v"]) or isset($options["verbose"])) {
$LOGGING_VERBOSITY = LoggingVerbosity::Debug;
}
if (isset($options["fast"])) {
$FAST_FETCH_MODE = true;
}
global $CACHE_ROOT, $ROOMS_FILE, $KNOWN_SERVERS, $KNOWN_PUBKEYS;
// Create default directories with conservative permissions.

@ -664,8 +664,10 @@
* @return array|false Associative data about rooms if successful.
*/
private function fetch_room_list(): array|bool {
global $FAST_FETCH_MODE;
$base_url = $this->base_url;
list($rooms, $downgrade) = curl_get_contents_downgrade("$base_url/rooms?all=1");
list($rooms, $downgrade) = curl_get_contents_downgrade("$base_url/rooms?all=1", retries: $FAST_FETCH_MODE ? 2 : 4);
if (!$rooms) {
log_info("Failed fetching /rooms.");
return false;
@ -726,6 +728,8 @@
* @return bool True if successful, false otherwise.
*/
function fetch_rooms(): bool {
global $FAST_FETCH_MODE;
$this->log_details();
$base_url = $this->base_url;
@ -733,7 +737,7 @@
if (count($this->room_hints) >= 2) {
log_info("Checking reachability for $base_url first...");
log_value($this->room_hints);
if (!url_is_reachable($base_url)) {
if (!url_is_reachable($base_url, retries: $FAST_FETCH_MODE ? 1 : 4)) {
log_warning("Reachability test failed by $base_url.");
return false;
}
@ -757,6 +761,8 @@
* @return bool True iff no key conflict has arised and we have a pubkey.
*/
function fetch_pubkey() {
global $FAST_FETCH_MODE;
if (empty($this->rooms)) {
log_warning("Server has no rooms to poll for public key");
return false;
@ -764,10 +770,14 @@
$has_pubkey = $this->has_pubkey();
if ($has_pubkey && $FAST_FETCH_MODE) {
return true;
}
$preview_url = $this->rooms[0]->get_preview_url();
log_info("Fetching pubkey from $preview_url");
$room_view = curl_get_contents($preview_url, retries: $has_pubkey ? 1 : 5);
$room_view = curl_get_contents($preview_url, retries: $has_pubkey || $FAST_FETCH_MODE ? 1 : 5);
if (!$room_view) {
log_debug("Failed to fetch room preview from $preview_url.");

Loading…
Cancel
Save