我创建了一个blog
表,其中有一个名为的字段views_count
,但我听说更新views_count
每个页面视图上的字段很麻烦。所以我现在创建了一个单独的视图计数表,如下所示:
views:
id,
blog_id,
ip_address,
counter
Run Code Online (Sandbox Code Playgroud)
现在我将独特的访问存储在views
表中。当我在视图表中保存记录时,我也会更新blog
字段views_count
字段,那么这是一个好方法吗?或者有更好的选择吗?
完整创建架构:
CREATE TABLE `video_blog` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`category_id` int(11) UNSIGNED DEFAULT NULL,
`title` varchar(255) NOT NULL,
`sub_title` varchar(255) DEFAULT NULL,
`slug` varchar(255) NOT NULL,
`video_embed_code` text,
`video_thumbnail` varchar(255) DEFAULT NULL,
`video_thumbnail_alt` varchar(255) DEFAULT NULL,
`description` text,
`views` int(11) UNSIGNED NOT NULL,
`is_active` tinyint(1) UNSIGNED NOT NULL DEFAULT '1',
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY …
Run Code Online (Sandbox Code Playgroud)