Refactor: Better Post Metrics data fetching
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user