Refactor: Better Post Metrics data fetching

This commit is contained in:
2024-05-15 00:41:28 +03:00
parent 196166897e
commit a6f3c6c695
8 changed files with 154 additions and 77 deletions
+13 -2
View File
@@ -1,9 +1,20 @@
import { getPosts } from '$lib/server/db/post';
import { getPostMetricsForPostId } from '$lib/server/db/postmertics';
/** @type {import('./$types').PageServerLoad} */
export async function load({ locals }) {
let result = await getPosts(locals.sql);
export async function load({ locals, url }) {
const result = await getPosts(locals.sql, undefined, 10, 0, true);
// const glance = url.searchParams.get('glance');
// const glanceID = glance ? parseInt(glance) : null
// let postMetrics = null;
// if (glanceID) {
// postMetrics = await getPostMetricsForPostId(glanceID);
// }
console.log(result);
return {
posts: result
+3 -1
View File
@@ -2,7 +2,9 @@
import Postlist from "$comp/postlist.svelte";
/**
* @type {{posts: import("$types/base").Post[]}}
* @type {{
* posts: import("$types/base").Post[]
* }}
*/
export let data;
</script>
@@ -1,6 +1,5 @@
import { getCommentsForPost } from "$lib/server/db/comment";
import { getPost } from "$lib/server/db/post";
import { getPostMetrics } from "$lib/server/db/postmertics";
import { getIdFromName } from "$lib/util";
import { error } from "@sveltejs/kit";
@@ -16,8 +15,6 @@ export async function load({ params, locals }) {
const comments = await getCommentsForPost(locals.sql, post_id);
console.log(await getPostMetrics(post));
return {
post: post,
comments: comments