Cache homepage projects in tags (#1336)

* Cache homepage projects in tags

* Update app page
This commit is contained in:
Geometrically 2024-07-31 12:37:51 -07:00 committed by GitHub
parent ae4f3759c2
commit 04b85630b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 67 additions and 45 deletions

View File

@ -17,4 +17,12 @@ jobs:
accountId: '9ddae624c98677d68d93df6e524a6061' accountId: '9ddae624c98677d68d93df6e524a6061'
project: 'frontend' project: 'frontend'
githubToken: ${{ secrets.GITHUB_TOKEN }} githubToken: ${{ secrets.GITHUB_TOKEN }}
commitHash: ${{ steps.push-changes.outputs.commit-hash }} commitHash: ${{ steps.push-changes.outputs.commit-hash }}
- name: Purge cache
if: github.ref == 'refs/heads/master'
run: |
curl -X \
-H "Authorization: ${{ secrets.CF_API_TOKEN }}" \
-H "Content-Type: application/json" \
--data '{"hosts": ["modrinth.com", "www.modrinth.com"]}' \
https://api.cloudflare.com/client/v4/zones/e39df17b9c4ef44cbce2646346ee6d33/purge_cache

View File

@ -122,6 +122,9 @@ export default defineNuxtConfig({
gameVersions?: any[]; gameVersions?: any[];
donationPlatforms?: any[]; donationPlatforms?: any[];
reportTypes?: any[]; reportTypes?: any[];
homePageProjects?: any[];
homePageSearch?: any[];
homePageNotifs?: any[];
} = {}; } = {};
try { try {
@ -153,21 +156,34 @@ export default defineNuxtConfig({
}, },
}; };
const [categories, loaders, gameVersions, donationPlatforms, reportTypes] = await Promise.all( const [
[ categories,
$fetch(`${API_URL}tag/category`, headers), loaders,
$fetch(`${API_URL}tag/loader`, headers), gameVersions,
$fetch(`${API_URL}tag/game_version`, headers), donationPlatforms,
$fetch(`${API_URL}tag/donation_platform`, headers), reportTypes,
$fetch(`${API_URL}tag/report_type`, headers), homePageProjects,
], homePageSearch,
); homePageNotifs,
] = await Promise.all([
$fetch(`${API_URL}tag/category`, headers),
$fetch(`${API_URL}tag/loader`, headers),
$fetch(`${API_URL}tag/game_version`, headers),
$fetch(`${API_URL}tag/donation_platform`, headers),
$fetch(`${API_URL}tag/report_type`, headers),
$fetch(`${API_URL}projects_random?count=60`, headers),
$fetch(`${API_URL}search?limit=3&query=leave&index=relevance`, headers),
$fetch(`${API_URL}search?limit=3&query=&index=updated`, headers),
]);
state.categories = categories; state.categories = categories;
state.loaders = loaders; state.loaders = loaders;
state.gameVersions = gameVersions; state.gameVersions = gameVersions;
state.donationPlatforms = donationPlatforms; state.donationPlatforms = donationPlatforms;
state.reportTypes = reportTypes; state.reportTypes = reportTypes;
state.homePageProjects = homePageProjects;
state.homePageSearch = homePageSearch;
state.homePageNotifs = homePageNotifs;
await fs.writeFile("./src/generated/state.json", JSON.stringify(state)); await fs.writeFile("./src/generated/state.json", JSON.stringify(state));

View File

@ -16,6 +16,8 @@ import ATLauncher from "~/assets/images/external/atlauncher.svg?component";
import CurseForge from "~/assets/images/external/curseforge.svg?component"; import CurseForge from "~/assets/images/external/curseforge.svg?component";
import Checkbox from "~/components/ui/Checkbox.vue"; import Checkbox from "~/components/ui/Checkbox.vue";
import { homePageProjects } from "~/generated/state.json";
const os = ref(null); const os = ref(null);
const macValue = ref(null); const macValue = ref(null);
const downloadWindows = ref(null); const downloadWindows = ref(null);
@ -34,19 +36,17 @@ const macLinks = {
let downloadLauncher; let downloadLauncher;
const [{ data: rows }, { data: launcherUpdates }] = await Promise.all([ const newProjects = homePageProjects.slice(0, 40);
useAsyncData("projects", () => useBaseFetch("projects_random?count=40"), { const val = Math.ceil(newProjects.length / 6);
transform: (homepageProjects) => { const rows = ref([
const val = Math.ceil(homepageProjects.length / 6); newProjects.slice(0, val),
return [ newProjects.slice(val, val * 2),
homepageProjects.slice(0, val), newProjects.slice(val * 2, val * 3),
homepageProjects.slice(val, val * 2), newProjects.slice(val * 3, val * 4),
homepageProjects.slice(val * 2, val * 3), newProjects.slice(val * 4, val * 5),
homepageProjects.slice(val * 3, val * 4), ]);
homepageProjects.slice(val * 4, val * 5),
]; const [{ data: launcherUpdates }] = await Promise.all([
},
}),
await useAsyncData("launcherUpdates", () => await useAsyncData("launcherUpdates", () =>
$fetch("https://launcher-files.modrinth.com/updates.json"), $fetch("https://launcher-files.modrinth.com/updates.json"),
), ),

View File

@ -513,34 +513,32 @@ import ATLauncherLogo from "~/assets/images/external/atlauncher.svg?component";
import Avatar from "~/components/ui/Avatar.vue"; import Avatar from "~/components/ui/Avatar.vue";
import ProjectCard from "~/components/ui/ProjectCard.vue"; import ProjectCard from "~/components/ui/ProjectCard.vue";
const searchQuery = ref("better"); import { homePageProjects, homePageSearch, homePageNotifs } from "~/generated/state.json";
const searchQuery = ref("leave");
const sortType = ref("relevance"); const sortType = ref("relevance");
const auth = await useAuth(); const auth = await useAuth();
const tags = useTags(); const tags = useTags();
const [ const newProjects = homePageProjects.slice(0, 40);
{ data: rows }, const val = Math.ceil(newProjects.length / 3);
{ data: searchProjects, refresh: updateSearchProjects }, const rows = ref([
{ data: notifications }, newProjects.slice(0, val),
] = await Promise.all([ newProjects.slice(val, val * 2),
useAsyncData("projects", () => useBaseFetch("projects_random?count=40"), { newProjects.slice(val * 2, val * 3),
transform: (result) => {
const val = Math.ceil(result.length / 3);
return [result.slice(0, val), result.slice(val, val * 2), result.slice(val * 2, val * 3)];
},
}),
useAsyncData(
"demoSearchProjects",
() => useBaseFetch(`search?limit=3&query=${searchQuery.value}&index=${sortType.value}`),
{
transform: (result) => result.hits,
},
),
useAsyncData("updatedProjects", () => useBaseFetch(`search?limit=3&query=&index=updated`), {
transform: (result) => result.hits,
}),
]); ]);
const notifications = ref(homePageNotifs.hits ?? []);
const searchProjects = ref(homePageSearch.hits ?? []);
async function updateSearchProjects() {
const res = await useBaseFetch(
`search?limit=3&query=${searchQuery.value}&index=${sortType.value}`,
);
searchProjects.value = res.hits ?? [];
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>