diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-06-19 19:19:57 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-06-19 20:21:17 -0700 |
commit | d8253db13c38e844c0d9d5580445675651879a2c (patch) | |
tree | 75bbcddee106d67b14ddd52343d05ae8aa8f4a38 /rust/src | |
parent | d2f50808ef9b96afc36d864adec74f10c9cea9af (diff) | |
download | fatcat-d8253db13c38e844c0d9d5580445675651879a2c.tar.gz fatcat-d8253db13c38e844c0d9d5580445675651879a2c.zip |
implement more of stats endpoint
Diffstat (limited to 'rust/src')
-rw-r--r-- | rust/src/api_server.rs | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index 7c84ad81..97ee93d6 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -119,7 +119,7 @@ macro_rules! count_entity { let count: i64 = $table::table .filter($table::is_live.eq(true)) .filter($table::redirect_id.is_null()) - .select(diesel::dsl::count($table::id)) + .count() .first($conn)?; count }}; @@ -890,11 +890,57 @@ impl Server { Ok(entries) } + /// "more" parameter isn't used, but could be to indicate that "expensive" database queries + /// should be run fn get_stats_handler(&self, _more: Option<String>) -> Result<StatsResponse> { let conn = self.db_pool.get().expect("db_pool error"); let merged_editgroups: i64 = changelog::table - .select(diesel::dsl::count(changelog::id)) + .select(diesel::dsl::count_star()) + .first(&conn)?; + let releases_with_dois: i64 = release_rev::table + .inner_join(release_ident::table) + .filter(release_rev::doi.is_not_null()) + .filter(release_ident::is_live.eq(true)) + .filter(release_ident::redirect_id.is_null()) + .select(diesel::dsl::count_star()) + .first(&conn)?; + let creators_with_orcids: i64 = creator_rev::table + .inner_join(creator_ident::table) + .filter(creator_rev::orcid.is_not_null()) + .filter(creator_ident::is_live.eq(true)) + .filter(creator_ident::redirect_id.is_null()) + .select(diesel::dsl::count_star()) + .first(&conn)?; + let containers_with_issnls: i64 = container_rev::table + .inner_join(container_ident::table) + .filter(container_rev::issnl.is_not_null()) + .filter(container_ident::is_live.eq(true)) + .filter(container_ident::redirect_id.is_null()) + .count() + .first(&conn)?; + + // these are probably expensive? + // this query is slightly inaccurate and over-counts: it includes files that have release + // links only to inactive releases + let files_with_releases: i64 = file_rev::table + .inner_join(file_ident::table) + .inner_join(file_release::table) + .filter(file_ident::is_live.eq(true)) + .filter(file_ident::redirect_id.is_null()) + .select(file_ident::id) + .distinct() + .count() + .first(&conn)?; + // this slightly overcounts also: it will include releases which are only linked to from + // inactive files + let releases_with_files: i64 = release_ident::table + .inner_join(file_release::table) + .filter(release_ident::is_live.eq(true)) + .filter(release_ident::redirect_id.is_null()) + .select(file_release::target_release_ident_id) + .distinct() + .count() .first(&conn)?; let val = json!({ @@ -906,11 +952,11 @@ impl Server { "work": count_entity!(work_ident, &conn), }, "merged_editgroups": merged_editgroups, - // TODO: "release_with_file": , - // TODO: "release_with_doi": , - // TODO: "creator_with_orcid": , - // TODO: "files_with_release": , - // TODO: "container_with_issnl": , + "releases_with_dois": releases_with_dois, + "creators_with_orcids": creators_with_orcids, + "containers_with_issnls": containers_with_issnls, + "files_with_releases": files_with_releases, + "releases_with_files": releases_with_files, }); Ok(StatsResponse { extra: Some(val) }) } |