aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/api_server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/api_server.rs')
-rw-r--r--rust/src/api_server.rs60
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) })
}