File tree 3 files changed +13
-20
lines changed 3 files changed +13
-20
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,8 @@ fn main() {
62
62
let app = cargo_registry:: App :: new ( & config) ;
63
63
let app = cargo_registry:: middleware ( Arc :: new ( app) ) ;
64
64
65
+ cargo_registry:: categories:: sync ( ) . unwrap ( ) ;
66
+
65
67
let port = if heroku {
66
68
8888
67
69
} else {
Original file line number Diff line number Diff line change 1
1
// Sync available crate categories from `src/categories.txt`.
2
- // Only needs to be run for new databases or when `src/categories.txt`
3
- // has been updated.
4
- //
5
- // Usage:
6
- // cargo run --bin sync-categories
2
+ // Runs when the server is started.
7
3
8
- #![ deny( warnings) ]
4
+ use pg;
5
+ use env;
6
+ use util:: errors:: CargoResult ;
9
7
10
- extern crate cargo_registry;
11
- extern crate postgres;
12
-
13
- use cargo_registry:: env;
14
-
15
- fn main ( ) {
16
- let conn = postgres:: Connection :: connect ( & env ( "DATABASE_URL" ) [ ..] ,
17
- postgres:: TlsMode :: None ) . unwrap ( ) ;
8
+ pub fn sync ( ) -> CargoResult < ( ) > {
9
+ let conn = pg:: Connection :: connect ( & env ( "DATABASE_URL" ) [ ..] ,
10
+ pg:: TlsMode :: None ) . unwrap ( ) ;
18
11
let tx = conn. transaction ( ) . unwrap ( ) ;
19
- sync ( & tx) . unwrap ( ) ;
20
- tx. set_commit ( ) ;
21
- tx. finish ( ) . unwrap ( ) ;
22
- }
23
12
24
- fn sync ( tx : & postgres:: transaction:: Transaction ) -> postgres:: Result < ( ) > {
25
- let categories = include_str ! ( "../categories.txt" ) ;
13
+ let categories = include_str ! ( "./categories.txt" ) ;
26
14
27
15
let slug_categories: Vec < _ > = categories. lines ( ) . map ( |c| {
28
16
let mut parts = c. split ( ' ' ) ;
@@ -50,5 +38,7 @@ fn sync(tx: &postgres::transaction::Transaction) -> postgres::Result<()> {
50
38
in_clause
51
39
) [ ..]
52
40
) ) ;
41
+ tx. set_commit ( ) ;
42
+ tx. finish ( ) . unwrap ( ) ;
53
43
Ok ( ( ) )
54
44
}
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ use conduit_middleware::MiddlewareBuilder;
52
52
use util:: { C , R , R404 } ;
53
53
54
54
pub mod app;
55
+ pub mod categories;
55
56
pub mod category;
56
57
pub mod config;
57
58
pub mod db;
You can’t perform that action at this time.
0 commit comments