Skip to content

Commit 750061b

Browse files
Nemo157Joshua Nelson
authored and
Joshua Nelson
committed
Use database ids to identify crates and versions
1 parent a214b46 commit 750061b

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/metrics/mod.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,25 @@ metrics! {
7979

8080
#[derive(Debug, Default)]
8181
pub(crate) struct RecentlyAccessedReleases {
82-
krates: DashMap<String, Instant>,
83-
versions: DashMap<String, Instant>,
84-
platforms: DashMap<String, Instant>,
82+
krates: DashMap<i32, Instant>,
83+
versions: DashMap<i32, Instant>,
84+
platforms: DashMap<(i32, String), Instant>,
8585
}
8686

8787
impl RecentlyAccessedReleases {
8888
pub(crate) fn new() -> Self {
8989
Self::default()
9090
}
9191

92-
pub(crate) fn record(&self, krate: &str, version: &str, target: &str) {
93-
self.krates.insert(krate.to_owned(), Instant::now());
94-
self.versions
95-
.insert(format!("{}/{}", krate, version), Instant::now());
92+
pub(crate) fn record(&self, krate: i32, version: i32, target: &str) {
93+
self.krates.insert(krate, Instant::now());
94+
self.versions.insert(version, Instant::now());
9695
self.platforms
97-
.insert(format!("{}/{}/{}", krate, version, target), Instant::now());
96+
.insert((version, target.to_owned()), Instant::now());
9897
}
9998

10099
pub(crate) fn gather(&self, metrics: &Metrics) {
101-
fn inner(map: &DashMap<String, Instant>, metric: &IntGaugeVec) {
100+
fn inner<K: std::hash::Hash + Eq>(map: &DashMap<K, Instant>, metric: &IntGaugeVec) {
102101
let mut hour_count = 0;
103102
let mut half_hour_count = 0;
104103
let mut five_minute_count = 0;

src/web/crate_details.rs

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub struct CrateDetails {
4545
documented_items: Option<f32>,
4646
total_items_needing_examples: Option<f32>,
4747
items_with_examples: Option<f32>,
48+
/// Database id for this crate
49+
pub(crate) crate_id: i32,
50+
/// Database id for this release
51+
pub(crate) release_id: i32,
4852
}
4953

5054
fn optional_markdown<S>(markdown: &Option<String>, serializer: S) -> Result<S::Ok, S::Error>
@@ -183,6 +187,8 @@ impl CrateDetails {
183187
total_items: total_items.map(|v| v as f32),
184188
total_items_needing_examples: total_items_needing_examples.map(|v| v as f32),
185189
items_with_examples: items_with_examples.map(|v| v as f32),
190+
crate_id,
191+
release_id,
186192
};
187193

188194
if let Some(repository_url) = crate_details.repository_url.clone() {

src/web/rustdoc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
425425

426426
metrics
427427
.recently_accessed_releases
428-
.record(&name, &version, target);
428+
.record(krate.crate_id, krate.release_id, target);
429429

430430
let target = if target == "" {
431431
String::new()

0 commit comments

Comments
 (0)