stat page and cache working
This commit is contained in:
@@ -256,6 +256,16 @@ export default function ManagePage() {
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
|
||||
</svg>
|
||||
</button>
|
||||
<Link
|
||||
href="/admin/manage/rust-status"
|
||||
className="px-4 py-3 sm:py-2 bg-teal-600 text-white rounded hover:bg-teal-700 transition-colors text-base font-medium flex items-center"
|
||||
title="Rust Parser Status"
|
||||
>
|
||||
<svg className="h-5 w-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 16h-1v-4h-1m1-4h.01M12 20a8 8 0 100-16 8 8 0 000 16z" />
|
||||
</svg>
|
||||
Rust Parser Status
|
||||
</Link>
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="px-4 py-3 sm:py-2 bg-red-600 text-white rounded hover:bg-red-700 text-base font-medium"
|
||||
|
||||
74
src/app/admin/manage/rust-status.tsx
Normal file
74
src/app/admin/manage/rust-status.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
interface PostStats {
|
||||
slug: string;
|
||||
cache_hits: number;
|
||||
cache_misses: number;
|
||||
last_interpret_time_ms: number;
|
||||
last_compile_time_ms: number;
|
||||
}
|
||||
|
||||
export default function RustStatusPage() {
|
||||
const [stats, setStats] = useState<PostStats[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const fetchStats = async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const res = await fetch('/api/admin/posts?rsparseinfo=1');
|
||||
if (!res.ok) throw new Error('Failed to fetch stats');
|
||||
const data = await res.json();
|
||||
setStats(data);
|
||||
} catch (e: any) {
|
||||
setError(e.message || 'Unknown error');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchStats();
|
||||
const interval = setInterval(fetchStats, 5000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="p-8 max-w-4xl mx-auto">
|
||||
<h1 className="text-2xl font-bold mb-6">Rust Parser Status</h1>
|
||||
{loading && <div>Loading...</div>}
|
||||
{error && <div className="text-red-500">{error}</div>}
|
||||
{!loading && !error && (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="min-w-full border border-gray-300 bg-white shadow-md rounded">
|
||||
<thead>
|
||||
<tr className="bg-gray-100">
|
||||
<th className="px-4 py-2 text-left">Slug</th>
|
||||
<th className="px-4 py-2 text-right">Cache Hits</th>
|
||||
<th className="px-4 py-2 text-right">Cache Misses</th>
|
||||
<th className="px-4 py-2 text-right">Last Interpret Time (ms)</th>
|
||||
<th className="px-4 py-2 text-right">Last Compile Time (ms)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{stats.length === 0 ? (
|
||||
<tr><td colSpan={5} className="text-center py-4">No stats available.</td></tr>
|
||||
) : (
|
||||
stats.map(stat => (
|
||||
<tr key={stat.slug} className="border-t">
|
||||
<td className="px-4 py-2 font-mono">{stat.slug}</td>
|
||||
<td className="px-4 py-2 text-right">{stat.cache_hits}</td>
|
||||
<td className="px-4 py-2 text-right">{stat.cache_misses}</td>
|
||||
<td className="px-4 py-2 text-right">{stat.last_interpret_time_ms}</td>
|
||||
<td className="px-4 py-2 text-right">{stat.last_compile_time_ms}</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
75
src/app/admin/manage/rust-status/page.tsx
Normal file
75
src/app/admin/manage/rust-status/page.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
'use client';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
interface PostStats {
|
||||
slug: string;
|
||||
cache_hits: number;
|
||||
cache_misses: number;
|
||||
last_interpret_time_ms: number;
|
||||
last_compile_time_ms: number;
|
||||
}
|
||||
|
||||
export default function RustStatusPage() {
|
||||
const [stats, setStats] = useState<PostStats[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const fetchStats = async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const res = await fetch('/api/admin/posts?rsparseinfo=1');
|
||||
if (!res.ok) throw new Error('Failed to fetch stats');
|
||||
const data = await res.json();
|
||||
setStats(data);
|
||||
} catch (e: any) {
|
||||
setError(e.message || 'Unknown error');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
fetchStats();
|
||||
const interval = setInterval(fetchStats, 5000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="p-8 max-w-4xl mx-auto">
|
||||
<h1 className="text-2xl font-bold mb-6">Rust Parser Status</h1>
|
||||
{loading && <div>Loading...</div>}
|
||||
{error && <div className="text-red-500">{error}</div>}
|
||||
{!loading && !error && (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="min-w-full border border-gray-300 bg-white shadow-md rounded">
|
||||
<thead>
|
||||
<tr className="bg-gray-100">
|
||||
<th className="px-4 py-2 text-left">Slug</th>
|
||||
<th className="px-4 py-2 text-right">Cache Hits</th>
|
||||
<th className="px-4 py-2 text-right">Cache Misses</th>
|
||||
<th className="px-4 py-2 text-right">Last Interpret Time (ms)</th>
|
||||
<th className="px-4 py-2 text-right">Last Compile Time (ms)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{stats.length === 0 ? (
|
||||
<tr><td colSpan={5} className="text-center py-4">No stats available.</td></tr>
|
||||
) : (
|
||||
stats.map(stat => (
|
||||
<tr key={stat.slug} className="border-t">
|
||||
<td className="px-4 py-2 font-mono">{stat.slug}</td>
|
||||
<td className="px-4 py-2 text-right">{stat.cache_hits}</td>
|
||||
<td className="px-4 py-2 text-right">{stat.cache_misses}</td>
|
||||
<td className="px-4 py-2 text-right">{stat.last_interpret_time_ms}</td>
|
||||
<td className="px-4 py-2 text-right">{stat.last_compile_time_ms}</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import matter from 'gray-matter';
|
||||
import { getPostsDirectory } from '@/lib/postsDirectory';
|
||||
import { spawnSync } from 'child_process';
|
||||
|
||||
const postsDirectory = getPostsDirectory();
|
||||
|
||||
@@ -48,6 +49,27 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const info = searchParams.get('rsparseinfo');
|
||||
if (info === '1') {
|
||||
// Call the Rust backend for parser stats
|
||||
const rustResult = spawnSync(
|
||||
process.cwd() + '/markdown_backend/target/release/markdown_backend',
|
||||
['rsparseinfo'],
|
||||
{ encoding: 'utf-8' }
|
||||
);
|
||||
if (rustResult.status === 0 && rustResult.stdout) {
|
||||
return new Response(rustResult.stdout, {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
} else {
|
||||
return new Response(JSON.stringify({ error: rustResult.stderr || rustResult.error }), {
|
||||
status: 500,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
}
|
||||
// Return the current pinned.json object
|
||||
try {
|
||||
const pinnedPath = path.join(process.cwd(), 'posts', 'pinned.json');
|
||||
|
||||
Reference in New Issue
Block a user