Skip to content

Commit a6e4588

Browse files
committed
Add crate_downloads table
1 parent a5df2a7 commit a6e4588

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
drop table crate_downloads;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
create table crate_downloads
2+
(
3+
crate_id integer not null
4+
constraint crate_downloads_pk
5+
primary key
6+
constraint crate_downloads_crates_id_fk
7+
references crates
8+
on delete cascade,
9+
downloads bigint default 0 not null
10+
);
11+
12+
comment on table crate_downloads is 'Number of downloads per crate. This was extracted from the `crates` table for performance reasons.';
13+
comment on column crate_downloads.crate_id is 'Reference to the crate that this row belongs to.';
14+
comment on column crate_downloads.downloads is 'The total number of downloads for this crate.';
15+
16+
-- The following query can take a couple of seconds so it should be run manually
17+
-- outside of the migration to prevent the server from taking a long time to
18+
-- start up while waiting for the migration to complete.
19+
20+
-- insert into crate_downloads (crate_id, downloads)
21+
-- select id, downloads
22+
-- from crates;

src/schema.patch

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
--- src/schema.rs.orig 2024-03-04 10:34:35
2+
+++ src/schema.rs 2024-03-04 10:33:35
13
@@ -21,9 +21,7 @@
24
/// The `pg_catalog.tsvector` SQL type
35
///
@@ -7,7 +9,7 @@
79
- pub struct Tsvector;
810
+ pub use diesel_full_text_search::Tsvector;
911
}
10-
12+
1113
diesel::table! {
1214
@@ -74,9 +72,9 @@
1315
/// (Automatically generated by Diesel.)
@@ -33,8 +35,8 @@
3335
- path -> Ltree,
3436
}
3537
}
36-
37-
@@ -456,7 +448,7 @@
38+
39+
@@ -476,7 +468,7 @@
3840
/// Its SQL type is `Array<Nullable<Text>>`.
3941
///
4042
/// (Automatically generated by Diesel.)
@@ -43,9 +45,9 @@
4345
/// The `target` column of the `dependencies` table.
4446
///
4547
/// Its SQL type is `Nullable<Varchar>`.
46-
@@ -683,6 +675,24 @@
48+
@@ -703,6 +695,24 @@
4749
}
48-
50+
4951
diesel::table! {
5052
+ /// Representation of the `recent_crate_downloads` view.
5153
+ ///
@@ -68,8 +70,8 @@
6870
/// Representation of the `reserved_crate_names` table.
6971
///
7072
/// (Automatically generated by Diesel.)
71-
@@ -997,7 +1007,8 @@
72-
diesel::joinable!(api_tokens -> users (user_id));
73+
@@ -1018,7 +1028,8 @@
74+
diesel::joinable!(crate_downloads -> crates (crate_id));
7375
diesel::joinable!(crate_owner_invitations -> crates (crate_id));
7476
diesel::joinable!(crate_owners -> crates (crate_id));
7577
-diesel::joinable!(crate_owners -> users (created_by));
@@ -78,15 +80,15 @@
7880
diesel::joinable!(crates_categories -> categories (category_id));
7981
diesel::joinable!(crates_categories -> crates (crate_id));
8082
diesel::joinable!(crates_keywords -> crates (crate_id));
81-
@@ -1010,6 +1021,7 @@
83+
@@ -1031,6 +1042,7 @@
8284
diesel::joinable!(publish_limit_buckets -> users (user_id));
8385
diesel::joinable!(publish_rate_overrides -> users (user_id));
8486
diesel::joinable!(readme_renderings -> versions (version_id));
8587
+diesel::joinable!(recent_crate_downloads -> crates (crate_id));
8688
diesel::joinable!(version_downloads -> versions (version_id));
8789
diesel::joinable!(version_owner_actions -> api_tokens (api_token_id));
8890
diesel::joinable!(version_owner_actions -> users (user_id));
89-
@@ -1036,6 +1048,7 @@
91+
@@ -1058,6 +1070,7 @@
9092
publish_limit_buckets,
9193
publish_rate_overrides,
9294
readme_renderings,

src/schema.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ diesel::table! {
181181
}
182182
}
183183

184+
diesel::table! {
185+
/// Number of downloads per crate. This was extracted from the `crates` table for performance reasons.
186+
crate_downloads (crate_id) {
187+
/// Reference to the crate that this row belongs to.
188+
crate_id -> Int4,
189+
/// The total number of downloads for this crate.
190+
downloads -> Int8,
191+
}
192+
}
193+
184194
diesel::table! {
185195
/// Representation of the `crate_owner_invitations` table.
186196
///
@@ -1005,6 +1015,7 @@ diesel::table! {
10051015
}
10061016

10071017
diesel::joinable!(api_tokens -> users (user_id));
1018+
diesel::joinable!(crate_downloads -> crates (crate_id));
10081019
diesel::joinable!(crate_owner_invitations -> crates (crate_id));
10091020
diesel::joinable!(crate_owners -> crates (crate_id));
10101021
diesel::joinable!(crate_owners -> teams (owner_id));
@@ -1034,6 +1045,7 @@ diesel::allow_tables_to_appear_in_same_query!(
10341045
api_tokens,
10351046
background_jobs,
10361047
categories,
1048+
crate_downloads,
10371049
crate_owner_invitations,
10381050
crate_owners,
10391051
crates,

src/worker/jobs/dump_db/dump-db.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ crates_cnt = "public"
4848
created_at = "public"
4949
path = "public"
5050

51+
[crate_downloads.columns]
52+
crate_id = "public"
53+
downloads = "public"
54+
5155
[crate_owner_invitations.columns]
5256
invited_user_id = "private"
5357
invited_by_user_id = "private"

0 commit comments

Comments
 (0)