opt: упростить счетчики - одна запись в БД вместо тысяч
- site_stats: 1 запись с полями today/total вместо site_visitors - posts: today_views + last_reset вместо post_views коллекции - Удалены старые коллекции site_visitors и post_views
This commit is contained in:
parent
62a6453a1a
commit
e7700a3391
6 changed files with 65 additions and 622 deletions
|
|
@ -320,22 +320,17 @@ const {
|
|||
|
||||
// 5. СЧЁТЧИК ПРОСМОТРОВ
|
||||
const viewsEl = document.querySelector('.meta-views') as HTMLElement & { dataset: { postId: string } };
|
||||
console.log('[Views] Element found:', viewsEl, 'postId:', viewsEl?.dataset?.postId);
|
||||
if (viewsEl?.dataset?.postId) {
|
||||
const postId = viewsEl.dataset.postId;
|
||||
console.log('[Views] Fetching for post:', postId);
|
||||
|
||||
fetch(`/api/increment-views?postId=${postId}`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
console.log('[Views] Response:', data);
|
||||
if (data.views !== undefined) {
|
||||
viewsEl.textContent = formatViews(data.views);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('[Views] Error:', err);
|
||||
});
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
function formatViews(n: number): string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue