Select Git revision
-
ale authored
The app is now self-hosted instead of relying on the static-content standalone server, so we can eventually add dynamic code for graph serving. The static content serving has improved, with more consistent cache header management, as well as the capability of serving pre-compressed content. Additional code to implement the generation of dependency (flow) graphs in dot format was added (not hooked to the HTTP server yet).
ale authoredThe app is now self-hosted instead of relying on the static-content standalone server, so we can eventually add dynamic code for graph serving. The static content serving has improved, with more consistent cache header management, as well as the capability of serving pre-compressed content. Additional code to implement the generation of dependency (flow) graphs in dot format was added (not hooked to the HTTP server yet).
wp-nginx-map-json.php 1.10 KiB
<?php
// wp-nginx-map.php (JSON version)
// Load wordpress api.
define('WP_CACHE',false);
require_once('/opt/noblogs/www/wp-load.php');
// Return all blogs.
function get_blogs() {
global $wpdb;
$sql = "SELECT blog_id, domain FROM $wpdb->blogs WHERE deleted = 0 AND archived = '0' ORDER BY domain ASC";
$result = $wpdb->get_results($sql);
return ($result);
}
function backend_to_shard_id($backend) {
if (substr($backend, 0, 8) != 'backend_') {
error_log('diamine, di questo backend non so che farmene: ' . $backend);
return '0';
}
return substr($backend, 8);
}
// Print the blog -> shard_id map.
function generate_shard_map($blogs) {
global $wpdb;
$wpdb_hash = &$wpdb->hash_map;
$shard_map = array();
foreach ($blogs as $blog) {
$blog_id = $blog->blog_id;
if ($blog_id == 1)
continue;
$backend_id = $wpdb_hash->lookup($blog_id);
$shard_id = backend_to_shard_id($backend_id);
$shard_map[$blog->domain] = $shard_id;
}
echo json_encode($shard_map);
}
function generate_maps() {
$all_blogs = get_blogs();
generate_shard_map($all_blogs);
}
generate_maps();