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

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

Loading…
Cancel
Save