aboutsummaryrefslogtreecommitdiff
path: root/src/constants.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-03-24 00:06:59 -0700
committerFuwn <[email protected]>2022-03-24 00:06:59 -0700
commit0ae95f06ed05a774137aab654857e3e26614c16e (patch)
treed06942db46df80474b77de6bfc993cd99d6af1bf /src/constants.rs
parentfeat(api): /me route (diff)
downloadapi-worker-0ae95f06ed05a774137aab654857e3e26614c16e.tar.xz
api-worker-0ae95f06ed05a774137aab654857e3e26614c16e.zip
feat: cache github api
This commit allows The Senpy Club API to cache GitHub's API response, refreshing the cache every fifty accesses. This commit also gets rid of a few dependencies which were replaced by their standard library counterparts.
Diffstat (limited to 'src/constants.rs')
-rw-r--r--src/constants.rs44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/constants.rs b/src/constants.rs
index 6f3e6e4..ad46dfd 100644
--- a/src/constants.rs
+++ b/src/constants.rs
@@ -16,27 +16,29 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use const_format::formatcp;
-
-lazy_static::lazy_static! {
- pub static ref INDEX: String = {
- format!(
- include_str!("index.rst"),
- format_args!(
- "https://github.com/senpy-club/api-worker/tree/{}",
- env!("VERGEN_GIT_SHA"),
- )
- )
- };
-}
+use std::lazy::SyncLazy;
const GITHUB_REPOSITORY: &str =
"cat-milk/Anime-Girls-Holding-Programming-Books";
-pub const GITHUB_USER_CONTENT: &str = formatcp!(
- "https://raw.githubusercontent.com/{}/master/",
- GITHUB_REPOSITORY
-);
-pub const GITHUB_API_ENDPOINT: &str = formatcp!(
- "https://api.github.com/repos/{}/git/trees/master?recursive=1",
- GITHUB_REPOSITORY,
-);
+
+pub static INDEX: SyncLazy<String> = SyncLazy::new(|| {
+ format!(
+ include_str!("index.rst"),
+ format_args!(
+ "https://github.com/senpy-club/api-worker/tree/{}",
+ env!("VERGEN_GIT_SHA"),
+ )
+ )
+});
+pub static GITHUB_USER_CONTENT: SyncLazy<String> = SyncLazy::new(|| {
+ format!(
+ "https://raw.githubusercontent.com/{}/master/",
+ GITHUB_REPOSITORY
+ )
+});
+pub static GITHUB_API_ENDPOINT: SyncLazy<String> = SyncLazy::new(|| {
+ format!(
+ "https://api.github.com/repos/{}/git/trees/master?recursive=1",
+ GITHUB_REPOSITORY,
+ )
+});