mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 03:55:07 +08:00
Pretty print the new dashboard numbers
This commit is contained in:
parent
d44428fa90
commit
f6eae91c7d
86
Cargo.lock
generated
86
Cargo.lock
generated
@ -18,6 +18,65 @@ version = "0.4.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b585a98a234c46fc563103e9278c9391fde1f4e6850334da895d27edb9580f62"
|
checksum = "b585a98a234c46fc563103e9278c9391fde1f4e6850334da895d27edb9580f62"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "askama"
|
||||||
|
version = "0.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "afb6c2f00d120a43d67345bbd3e9e21d1ee090c1fc7db7787c05bd969b83bccf"
|
||||||
|
dependencies = [
|
||||||
|
"askama_derive",
|
||||||
|
"askama_escape",
|
||||||
|
"askama_shared",
|
||||||
|
"mime 0.3.16",
|
||||||
|
"mime_guess 2.0.3",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "askama_derive"
|
||||||
|
version = "0.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6d97b96db4caba8842ec48a537cab1e6d7e809d7a408c97ae99f129e1c982750"
|
||||||
|
dependencies = [
|
||||||
|
"askama_shared",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "askama_escape"
|
||||||
|
version = "0.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "90c108c1a94380c89d2215d0ac54ce09796823cca0fd91b299cfff3b33e346fb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "askama_shared"
|
||||||
|
version = "0.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3342887c2f85a336bc8bc4fc79603434539cdae37565e20ccf54599dea8e42ee"
|
||||||
|
dependencies = [
|
||||||
|
"askama_escape",
|
||||||
|
"humansize",
|
||||||
|
"nom",
|
||||||
|
"num-traits",
|
||||||
|
"percent-encoding",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"serde",
|
||||||
|
"syn",
|
||||||
|
"toml",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "askama_warp"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c96f410ab17fa08f70b5fda07ce1112418642c914864961630808979343ea226"
|
||||||
|
dependencies = [
|
||||||
|
"askama",
|
||||||
|
"warp",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atty"
|
name = "atty"
|
||||||
version = "0.2.14"
|
version = "0.2.14"
|
||||||
@ -654,6 +713,12 @@ version = "1.3.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
|
checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "humansize"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper"
|
name = "hyper"
|
||||||
version = "0.13.6"
|
version = "0.13.6"
|
||||||
@ -847,6 +912,8 @@ name = "mega-mini-indexer"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"askama",
|
||||||
|
"askama_warp",
|
||||||
"bitpacking",
|
"bitpacking",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"cow-utils",
|
"cow-utils",
|
||||||
@ -1038,6 +1105,16 @@ dependencies = [
|
|||||||
"winapi 0.3.8",
|
"winapi 0.3.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nom"
|
||||||
|
version = "5.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"version_check 0.9.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-traits"
|
name = "num-traits"
|
||||||
version = "0.2.12"
|
version = "0.2.12"
|
||||||
@ -1824,6 +1901,15 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "0.5.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower-service"
|
name = "tower-service"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
@ -34,6 +34,8 @@ indexmap = "1.4.0"
|
|||||||
itertools = "0.9.0"
|
itertools = "0.9.0"
|
||||||
|
|
||||||
# http server
|
# http server
|
||||||
|
askama = "0.10.1"
|
||||||
|
askama_warp = "0.10.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tokio = { version = "0.2.15", features = ["full"] }
|
tokio = { version = "0.2.15", features = ["full"] }
|
||||||
warp = "0.2.2"
|
warp = "0.2.2"
|
||||||
|
6
public/filesize.min.js
vendored
Normal file
6
public/filesize.min.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/*
|
||||||
|
2020 Jason Mulligan <jason.mulligan@avoidwork.com>
|
||||||
|
@version 6.1.0
|
||||||
|
*/
|
||||||
|
"use strict";!function(e){var x=/^(b|B)$/,M={iec:{bits:["b","Kib","Mib","Gib","Tib","Pib","Eib","Zib","Yib"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["b","Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},w={iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]};function t(e){var i,t,o,n,b,r,a,l,s,d,u,c,f,p,B,y=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},g=[],v=0,m=void 0,h=void 0;if(isNaN(e))throw new TypeError("Invalid number");return t=!0===y.bits,u=!0===y.unix,i=y.base||2,d=void 0!==y.round?y.round:u?1:2,r=void 0!==y.locale?y.locale:"",a=y.localeOptions||{},c=void 0!==y.separator?y.separator:"",f=void 0!==y.spacer?y.spacer:u?"":" ",B=y.symbols||{},p=2===i&&y.standard||"jedec",s=y.output||"string",n=!0===y.fullform,b=y.fullforms instanceof Array?y.fullforms:[],m=void 0!==y.exponent?y.exponent:-1,o=2<i?1e3:1024,(l=(h=Number(e))<0)&&(h=-h),(-1===m||isNaN(m))&&(m=Math.floor(Math.log(h)/Math.log(o)))<0&&(m=0),8<m&&(m=8),"exponent"===s?m:(0===h?(g[0]=0,g[1]=u?"":M[p][t?"bits":"bytes"][m]):(v=h/(2===i?Math.pow(2,10*m):Math.pow(1e3,m)),t&&o<=(v*=8)&&m<8&&(v/=o,m++),g[0]=Number(v.toFixed(0<m?d:0)),g[0]===o&&m<8&&void 0===y.exponent&&(g[0]=1,m++),g[1]=10===i&&1===m?t?"kb":"kB":M[p][t?"bits":"bytes"][m],u&&(g[1]="jedec"===p?g[1].charAt(0):0<m?g[1].replace(/B$/,""):g[1],x.test(g[1])&&(g[0]=Math.floor(g[0]),g[1]=""))),l&&(g[0]=-g[0]),g[1]=B[g[1]]||g[1],!0===r?g[0]=g[0].toLocaleString():0<r.length?g[0]=g[0].toLocaleString(r,a):0<c.length&&(g[0]=g[0].toString().replace(".",c)),"array"===s?g:(n&&(g[1]=b[m]?b[m]:w[p][m]+(t?"bit":"byte")+(1===g[0]?"":"s")),"object"===s?{value:g[0],symbol:g[1],exponent:m}:g.join(f)))}t.partial=function(i){return function(e){return t(e,i)}},"undefined"!=typeof exports?module.exports=t:"function"==typeof define&&void 0!==define.amd?define(function(){return t}):e.filesize=t}("undefined"!=typeof window?window:global);
|
||||||
|
//# sourceMappingURL=filesize.min.js.map
|
@ -53,3 +53,13 @@ $('#search').on('input', function () {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Make the number of document a little bit prettier
|
||||||
|
$('#docs-count').text(function(index, text) {
|
||||||
|
return parseInt(text).toLocaleString()
|
||||||
|
});
|
||||||
|
|
||||||
|
// Make the database a little bit easier to read
|
||||||
|
$('#db-size').text(function(index, text) {
|
||||||
|
return filesize(parseInt(text))
|
||||||
|
});
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
use std::fs::File;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use askama_warp::Template;
|
||||||
use heed::EnvOpenOptions;
|
use heed::EnvOpenOptions;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
@ -32,6 +34,14 @@ struct Opt {
|
|||||||
http_listen_addr: String,
|
http_listen_addr: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "index.html")]
|
||||||
|
struct IndexTemplate {
|
||||||
|
db_name: String,
|
||||||
|
db_size: usize,
|
||||||
|
docs_count: usize,
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
@ -44,12 +54,29 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let index = Index::new(&env)?;
|
let index = Index::new(&env)?;
|
||||||
|
|
||||||
|
// Retrieve the database the file stem (w/o the extension)
|
||||||
|
let db_name = opt.database.file_stem().and_then(|s| s.to_str()).unwrap_or("").to_string();
|
||||||
|
|
||||||
|
// Retrieve the disk file size
|
||||||
|
let db_size = File::open(opt.database.join("data.mdb"))?.metadata()?.len() as usize;
|
||||||
|
|
||||||
|
// Precompute the number of documents in the database.
|
||||||
|
let rtxn = env.read_txn().unwrap();
|
||||||
|
let docs_count = index.documents.len(&rtxn)?;
|
||||||
|
drop(rtxn);
|
||||||
|
|
||||||
// We run and wait on the HTTP server
|
// We run and wait on the HTTP server
|
||||||
|
|
||||||
// Expose an HTML page to debug the search in a browser
|
// Expose an HTML page to debug the search in a browser
|
||||||
let dash_html_route = warp::filters::method::get()
|
let dash_html_route = warp::filters::method::get()
|
||||||
.and(warp::filters::path::end())
|
.and(warp::filters::path::end())
|
||||||
.map(|| warp::reply::html(include_str!("../../public/index.html")));
|
.map(move || {
|
||||||
|
IndexTemplate {
|
||||||
|
db_name: db_name.clone(),
|
||||||
|
db_size,
|
||||||
|
docs_count,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let dash_bulma_route = warp::filters::method::get()
|
let dash_bulma_route = warp::filters::method::get()
|
||||||
.and(warp::path!("bulma.min.css"))
|
.and(warp::path!("bulma.min.css"))
|
||||||
@ -79,6 +106,13 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
.body(include_str!("../../public/papaparse.min.js"))
|
.body(include_str!("../../public/papaparse.min.js"))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let dash_filesize_route = warp::filters::method::get()
|
||||||
|
.and(warp::path!("filesize.min.js"))
|
||||||
|
.map(|| Response::builder()
|
||||||
|
.header("content-type", "application/javascript; charset=utf-8")
|
||||||
|
.body(include_str!("../../public/filesize.min.js"))
|
||||||
|
);
|
||||||
|
|
||||||
let dash_script_route = warp::filters::method::get()
|
let dash_script_route = warp::filters::method::get()
|
||||||
.and(warp::path!("script.js"))
|
.and(warp::path!("script.js"))
|
||||||
.map(|| Response::builder()
|
.map(|| Response::builder()
|
||||||
@ -124,6 +158,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
.or(dash_style_route)
|
.or(dash_style_route)
|
||||||
.or(dash_jquery_route)
|
.or(dash_jquery_route)
|
||||||
.or(dash_papaparse_route)
|
.or(dash_papaparse_route)
|
||||||
|
.or(dash_filesize_route)
|
||||||
.or(dash_script_route)
|
.or(dash_script_route)
|
||||||
.or(query_route);
|
.or(query_route);
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
<link rel="stylesheet" href="/style.css">
|
<link rel="stylesheet" href="/style.css">
|
||||||
<script type="text/javascript" src="/jquery-3.4.1.min.js"></script>
|
<script type="text/javascript" src="/jquery-3.4.1.min.js"></script>
|
||||||
<script type="text/javascript" src="/papaparse.min.js"></script>
|
<script type="text/javascript" src="/papaparse.min.js"></script>
|
||||||
<title>The milli engine</title>
|
<script type="text/javascript" src="/filesize.min.js"></script>
|
||||||
|
<title>{{ db_name }} | The milli engine</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
@ -20,20 +21,20 @@
|
|||||||
<nav class="level">
|
<nav class="level">
|
||||||
<div class="level-item has-text-centered">
|
<div class="level-item has-text-centered">
|
||||||
<div>
|
<div>
|
||||||
<p class="heading">Database Name</p>
|
<p class="heading">Database Path</p>
|
||||||
<p class="title">songs-2.mmdb</p>
|
<p class="title">{{ db_name }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="level-item has-text-centered">
|
<div class="level-item has-text-centered">
|
||||||
<div>
|
<div>
|
||||||
<p class="heading">Database Size</p>
|
<p class="heading">Database Size</p>
|
||||||
<p class="title">123 MB</p>
|
<p class="title" id="db-size">{{ db_size }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="level-item has-text-centered">
|
<div class="level-item has-text-centered">
|
||||||
<div>
|
<div>
|
||||||
<p class="heading">Number of Documents</p>
|
<p class="heading">Number of Documents</p>
|
||||||
<p class="title">456 K</p>
|
<p class="title" id="docs-count">{{ docs_count }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
Loading…
Reference in New Issue
Block a user