优化记录存储

This commit is contained in:
2023-11-07 10:04:54 +08:00
parent aed08bc7a1
commit 789d1dc395
5 changed files with 46 additions and 44 deletions

View File

@@ -41,28 +41,28 @@ class Common extends BaseController
$list_nav_more = Nav::where('type', 8)->cacheAlways('type_list_8')->order('sort asc')->where('status', 1)->select();
View::assign('list_nav_more', $list_nav_more);
$top_posts = Post::where('is_top', 1)->limit(8)->where('type', 3)->cacheAlways('top_post')->select();
$top_posts = Post::where('is_top', 1)->limit(8)->where('type', 3)->cacheAlways(60)->select();
View::assign('top_posts', $top_posts);
$list_site_last_visit = PostVisit::with(['post'])->order('id desc')
->group('post_id,ip,uid')
->limit(6)
->cache(60)
->cacheAlways(60)
->select();
View::assign('list_site_last_visit', $list_site_last_visit);
$total_hits = Post::cache(60)->sum('hits');
$total_hits = Post::cacheAlways(60)->sum('hits');
View::assign('total_hits', $total_hits);
$total_week_hits = PostVisit::cache(60)->where('create_time', '>', strtotime(date('Y-m-d 00:00:00')) - 86400 * 7)->count();
$total_day_hits = PostVisit::cache(60)->where('create_time', '>', strtotime(date('Y-m-d 00:00:00')))->count();
$total_week_hits = PostVisit::cacheAlways(60)->where('create_time', '>', strtotime(date('Y-m-d 00:00:00')) - 86400 * 7)->count();
$total_day_hits = PostVisit::cacheAlways(60)->where('create_time', '>', strtotime(date('Y-m-d 00:00:00')))->count();
View::assign('total_week_hits', $total_week_hits);
View::assign('total_day_hits', $total_day_hits);
$total_post_count = Post::cache(60)->where('status', 1)->where('type', 3)->count();
$total_post_count = Post::cacheAlways(60)->where('status', 1)->where('type', 3)->count();
View::assign('total_post_count', $total_post_count);
$total_month_post_count = Post::cache(60)->where('status', 1)->where('type', 3)->where('publish_time', '>', strtotime(date('Y-m-1 00:00:00')))->count();
$total_month_post_count = Post::cacheAlways(60)->where('status', 1)->where('type', 3)->where('publish_time', '>', strtotime(date('Y-m-1 00:00:00')))->count();
View::assign('total_month_post_count', $total_month_post_count);
$this->userHubLogin();

View File

@@ -14,6 +14,13 @@ use think\model\Relation;
class Post extends Common
{
public function initialize()
{
if ($this->request->action() != 'markVisit') {
parent::initialize();
}
}
/**
* 显示指定的资源.
*
@@ -52,6 +59,7 @@ class Post extends Common
->limit(12)
->cache(60)
->select();
View::assign('post', $model_post);
View::assign('list_last_visit', $list_last_visit);
@@ -96,9 +104,7 @@ class Post extends Common
public function markVisit($visit_id)
{
$model_visit = PostVisit::find($visit_id);
$model_visit->is_js_run = 1;
$model_visit->save();
PostVisit::where('id', $visit_id)->update(['is_js_run' => 1]);
return json_message();
}