Use git-style subdirectories for data files.

- To address scalability concerns, we put data files into
    subdirectories by splitting e.g. the fingerprint into a two
    character prefix and the rest, using the prefix as subdirectory
    name, and the rest as filename.

  - We hide this fact from the user using rewrite rules in nginx.

  - Fixes #38.
This commit is contained in:
Justus Winter 2019-02-22 00:29:15 +01:00
parent c90c5dc696
commit 3de0164fd9
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
2 changed files with 18 additions and 9 deletions

View File

@ -21,19 +21,22 @@ http {
root dist/public;
location ^~ /by-email/ {
location /by-email/ {
rewrite ^/by-email/([^/][^/])(..*)$ /by-email/$1/$2 break;
default_type application/pgp-keys;
try_files /$request_uri =404;
try_files /$uri =404;
}
location ^~ /by-fingerprint/ {
location /by-fingerprint/ {
rewrite ^/by-fingerprint/([^/][^/])(..*)$ /by-fingerprint/$1/$2 break;
default_type application/pgp-keys;
try_files /$request_uri =404;
try_files /$uri =404;
}
location ^~ /by-keyid/ {
location /by-keyid/ {
rewrite ^/by-keyid/([^/][^/])(.*)$ /by-keyid/$1/$2 break;
default_type application/pgp-keys;
try_files /$request_uri =404;
try_files /$uri =404;
}
location = / {

View File

@ -94,17 +94,23 @@ impl Filesystem {
/// Returns the path to the given KeyID.
fn path_to_keyid(&self, keyid: &KeyID) -> PathBuf {
self.base_by_keyid.join(keyid.to_string())
let hex = keyid.to_string();
self.base_by_keyid.join(&hex[..2]).join(&hex[2..])
}
/// Returns the path to the given Fingerprint.
fn path_to_fingerprint(&self, fingerprint: &Fingerprint) -> PathBuf {
self.base_by_fingerprint.join(fingerprint.to_string())
let hex = fingerprint.to_string();
self.base_by_fingerprint.join(&hex[..2]).join(&hex[2..])
}
/// Returns the path to the given Email.
fn path_to_email(&self, email: &str) -> PathBuf {
self.base_by_email.join(email.to_string())
if email.len() > 2 {
self.base_by_email.join(&email[..2]).join(&email[2..])
} else {
self.base_by_email.join(email)
}
}
fn new_token<'a>(&self, base: &'a str) -> Result<(File, String)> {