File tree 2 files changed +15
-2
lines changed
2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -428,6 +428,7 @@ public function show($id)
428
428
429
429
$ pollSummary = PollOption::summary ($ topic , $ currentUser );
430
430
431
+ $ topic ->incrementViewCount ($ currentUser , \Request::ip ());
431
432
$ posts ->last ()->markRead ($ currentUser );
432
433
433
434
$ coverModel = $ topic ->cover ?? new TopicCover ();
Original file line number Diff line number Diff line change @@ -103,6 +103,8 @@ class Topic extends Model implements AfterCommit
103
103
'topic_title ' => 100 ,
104
104
];
105
105
106
+ const VIEW_COUNT_INTERVAL = 86400 ; // 1 day
107
+
106
108
protected $ table = 'phpbb_topics ' ;
107
109
protected $ primaryKey = 'topic_id ' ;
108
110
@@ -541,8 +543,6 @@ public function markRead($user, $markTime)
541
543
542
544
throw $ ex ;
543
545
}
544
-
545
- $ this ->incrementInstance ('topic_views ' );
546
546
} elseif ($ status ->mark_time < $ markTime ) {
547
547
$ status ->update (['mark_time ' => $ markTime ]);
548
548
}
@@ -555,6 +555,18 @@ public function markRead($user, $markTime)
555
555
DB ::commit ();
556
556
}
557
557
558
+ public function incrementViewCount (?User $ user , string $ ipAddr ): void
559
+ {
560
+ $ lockKey = "view:forum_topic: {$ this ->getKey ()}: " ;
561
+ $ lockKey .= $ user === null
562
+ ? "guest: {$ ipAddr }"
563
+ : "user: {$ user ->getKey ()}" ;
564
+
565
+ if (\Cache::lock ($ lockKey , static ::VIEW_COUNT_INTERVAL )->get ()) {
566
+ $ this ->incrementInstance ('topic_views ' );
567
+ }
568
+ }
569
+
558
570
public function isIssue ()
559
571
{
560
572
return in_array ($ this ->forum_id , $ GLOBALS ['cfg ' ]['osu ' ]['forum ' ]['issue_forum_ids ' ], true );
You can’t perform that action at this time.
0 commit comments