Skip to content

Commit 8eef24d

Browse files
committed
Merge remote-tracking branch 'upstream/master' into sitemap-split
2 parents b5008f8 + ce51a77 commit 8eef24d

File tree

10 files changed

+82
-21
lines changed

10 files changed

+82
-21
lines changed

src/db/add_package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub(crate) fn add_package_into_database(
9292
&[
9393
&crate_id,
9494
&metadata_pkg.version,
95-
&registry_data.release_time.naive_utc(),
95+
&registry_data.release_time,
9696
&serde_json::to_value(&dependencies)?,
9797
&metadata_pkg.package_name(),
9898
&registry_data.yanked,

src/db/migrate.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,49 @@ pub fn migrate(version: Option<Version>, conn: &mut Client) -> CratesfyiResult<(
556556
ADD COLUMN github_last_update TIMESTAMP;
557557
"
558558
),
559+
migration!(
560+
context,
561+
24,
562+
"migrate timestamp to be timezone aware",
563+
// upgrade
564+
"
565+
ALTER TABLE builds
566+
ALTER build_time TYPE timestamptz USING build_time AT TIME ZONE 'UTC';
567+
568+
ALTER TABLE files
569+
ALTER date_added TYPE timestamptz USING date_added AT TIME ZONE 'UTC',
570+
ALTER date_updated TYPE timestamptz USING date_updated AT TIME ZONE 'UTC';
571+
572+
ALTER TABLE github_repos
573+
ALTER updated_at TYPE timestamptz USING updated_at AT TIME ZONE 'UTC',
574+
ALTER last_commit TYPE timestamptz USING last_commit AT TIME ZONE 'UTC';
575+
576+
ALTER TABLE queue
577+
ALTER date_added TYPE timestamptz USING date_added AT TIME ZONE 'UTC';
578+
579+
ALTER TABLE releases
580+
ALTER release_time TYPE timestamptz USING release_time AT TIME ZONE 'UTC';
581+
",
582+
// downgrade
583+
"
584+
ALTER TABLE builds
585+
ALTER build_time TYPE timestamp USING build_time AT TIME ZONE 'UTC';
586+
587+
ALTER TABLE files
588+
ALTER date_added TYPE timestamp USING date_added AT TIME ZONE 'UTC',
589+
ALTER date_updated TYPE timestamp USING date_updated AT TIME ZONE 'UTC';
590+
591+
ALTER TABLE github_repos
592+
ALTER updated_at TYPE timestamp USING updated_at AT TIME ZONE 'UTC',
593+
ALTER last_commit TYPE timestamp USING last_commit AT TIME ZONE 'UTC';
594+
595+
ALTER TABLE queue
596+
ALTER date_added TYPE timestamp USING date_added AT TIME ZONE 'UTC';
597+
598+
ALTER TABLE releases
599+
ALTER release_time TYPE timestamp USING release_time AT TIME ZONE 'UTC';
600+
",
601+
),
559602
];
560603

561604
for migration in migrations {

src/storage/database.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::{Blob, StorageTransaction};
22
use crate::db::Pool;
33
use crate::Metrics;
4-
use chrono::{DateTime, NaiveDateTime, Utc};
54
use failure::Error;
65
use postgres::Transaction;
76
use std::sync::Arc;
@@ -61,7 +60,7 @@ impl DatabaseBackend {
6160
Ok(Blob {
6261
path: row.get("path"),
6362
mime: row.get("mime"),
64-
date_updated: DateTime::from_utc(row.get::<_, NaiveDateTime>("date_updated"), Utc),
63+
date_updated: row.get("date_updated"),
6564
content: row.get("content"),
6665
compression,
6766
})

src/web/builds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
impl_webpage,
55
web::{page::WebPage, MetaData},
66
};
7-
use chrono::{DateTime, NaiveDateTime, Utc};
7+
use chrono::{DateTime, Utc};
88
use iron::{
99
headers::{
1010
AccessControlAllowOrigin, CacheControl, CacheDirective, ContentType, Expires, HttpDate,
@@ -80,7 +80,7 @@ pub fn build_list_handler(req: &mut Request) -> IronResult<Response> {
8080
rustc_version: row.get("rustc_version"),
8181
docsrs_version: row.get("cratesfyi_version"),
8282
build_status: row.get("build_status"),
83-
build_time: DateTime::from_utc(row.get::<_, NaiveDateTime>("build_time"), Utc),
83+
build_time: row.get("build_time"),
8484
output: row.get("output"),
8585
};
8686

src/web/crate_details.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{match_version, redirect_base, render_markdown, MatchSemver, MetaData};
22
use crate::{db::Pool, impl_webpage, web::page::WebPage};
3-
use chrono::{DateTime, NaiveDateTime, Utc};
3+
use chrono::{DateTime, Utc};
44
use iron::prelude::*;
55
use iron::Url;
66
use postgres::Client;
@@ -181,7 +181,7 @@ impl CrateDetails {
181181
dependencies: krate.get("dependencies"),
182182
readme: krate.get("readme"),
183183
rustdoc: krate.get("description_long"),
184-
release_time: DateTime::from_utc(krate.get::<_, NaiveDateTime>("release_time"), Utc),
184+
release_time: krate.get("release_time"),
185185
build_status: krate.get("build_status"),
186186
last_successful_build: None,
187187
rustdoc_status: krate.get("rustdoc_status"),

src/web/releases.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
web::{error::Nope, match_version, page::WebPage, redirect_base},
88
BuildQueue,
99
};
10-
use chrono::{DateTime, NaiveDateTime, Utc};
10+
use chrono::{DateTime, Utc};
1111
use iron::{
1212
headers::{ContentType, Expires, HttpDate},
1313
mime::{Mime, SubLevel, TopLevel},
@@ -102,7 +102,7 @@ pub(crate) fn get_releases(conn: &mut Client, page: i64, limit: i64, order: Orde
102102
version: row.get(1),
103103
description: row.get(2),
104104
target_name: row.get(3),
105-
release_time: DateTime::from_utc(row.get::<_, NaiveDateTime>(4), Utc),
105+
release_time: row.get(4),
106106
rustdoc_status: row.get(5),
107107
stars: row.get::<_, Option<i32>>(6).unwrap_or(0),
108108
})
@@ -149,7 +149,7 @@ fn get_releases_by_author(
149149
version: row.get(1),
150150
description: row.get(2),
151151
target_name: row.get(3),
152-
release_time: DateTime::from_utc(row.get::<_, NaiveDateTime>(4), Utc),
152+
release_time: row.get(4),
153153
rustdoc_status: row.get(5),
154154
stars: row.get::<_, Option<i32>>(6).unwrap_or(0),
155155
}
@@ -203,7 +203,7 @@ fn get_releases_by_owner(
203203
version: row.get(1),
204204
description: row.get(2),
205205
target_name: row.get(3),
206-
release_time: DateTime::from_utc(row.get::<_, NaiveDateTime>(4), Utc),
206+
release_time: row.get(4),
207207
rustdoc_status: row.get(5),
208208
stars: row.get::<_, Option<i32>>(6).unwrap_or(0),
209209
}
@@ -286,7 +286,7 @@ fn get_search_results(
286286
version: row.get("version"),
287287
description: row.get("description"),
288288
target_name: row.get("target_name"),
289-
release_time: DateTime::from_utc(row.get("release_time"), Utc),
289+
release_time: row.get("release_time"),
290290
rustdoc_status: row.get("rustdoc_status"),
291291
stars: row.get::<_, Option<i32>>("github_stars").unwrap_or(0),
292292
})

src/web/sitemap.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{db::Pool, docbuilder::Limits, impl_webpage, web::error::Nope, web::page::WebPage};
2-
use chrono::{DateTime, NaiveDateTime, Utc};
2+
use chrono::{DateTime, Utc};
33
use iron::{
44
headers::ContentType,
55
mime::{Mime, SubLevel, TopLevel},
@@ -80,9 +80,7 @@ pub fn sitemap_handler(req: &mut Request) -> IronResult<Response> {
8080
let releases = query
8181
.into_iter()
8282
.map(|row| {
83-
let time = DateTime::<Utc>::from_utc(row.get::<_, NaiveDateTime>(1), Utc)
84-
.format("%+")
85-
.to_string();
83+
let time = row.get::<_, DateTime<Utc>>(1).format("%+").to_string();
8684

8785
(row.get(0), time)
8886
})

templates/base.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
<link rel="stylesheet" href="/-/static/vendored.css?{{ docsrs_version() | slugify }}" type="text/css" media="all" />
1414
<link rel="stylesheet" href="/-/static/style.css?{{ docsrs_version() | slugify }}" type="text/css" media="all" />
1515

16-
{%- block css -%}{%- endblock css -%}
17-
1816
<link rel="search" href="/-/static/opensearch.xml" type="application/opensearchdescription+xml" title="Docs.rs" />
1917

2018
<title>{%- block title -%} Docs.rs {%- endblock title -%}</title>
2119

2220
<script type="text/javascript">{%- include "theme.js" -%}</script>
21+
{%- block css -%}{%- endblock css -%}
2322
</head>
2423

2524
<body>

templates/macros.html

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,30 @@
2222
{# Makes the appropriate CSS imports for highlighting #}
2323
{% macro highlight_css() %}
2424
{# Load the highlighting theme css #}
25-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.4.0/styles/github.min.css"
26-
type="text/css" media="all" />
25+
<script>
26+
// Choose which highlight.js theme to load based on the user theme
27+
var stylesheet;
28+
switch(document.documentElement.dataset.theme) {
29+
case "dark":
30+
case "ayu":
31+
stylesheet = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.4.0/styles/dark.min.css";
32+
break;
33+
case "null": // The user is visiting docs.rs for the first time and hasn't set a theme yet.
34+
case "light":
35+
stylesheet = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.4.0/styles/github.min.css";
36+
break;
37+
default:
38+
throw "unrecognized theme " + document.documentElement.dataset.theme;
39+
break;
40+
}
41+
// Now add the stylesheet to the document
42+
var link = document.createElement("link");
43+
link.rel = "stylesheet";
44+
link.href = stylesheet;
45+
link.type = "text/css";
46+
link.media = "all";
47+
document.head.appendChild(link);
48+
</script>
2749
{% endmacro highlight_css %}
2850

2951
{#

templates/style/base.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ body {
9797
border-bottom: 1px solid;
9898
}
9999
pre {
100-
background-color: #F5F5F5;
100+
background-color: var(--color-background-code);
101101
padding: 14px;
102102
}
103103
code, kbd, pre, samp {

0 commit comments

Comments
 (0)