@@ -22,38 +22,39 @@ public function handle()
2222 $ count = 0 ;
2323 $ now = now ();
2424
25- Instance::query ()
26- -> where ( function ( $ query ) {
27- $ query -> whereNull ('stats_last_collected_at ' )
28- -> orWhere ( ' stats_last_collected_at ' , ' < ' , now ()-> subDay ());
29- } )
25+ $ instances = Instance::where ( function ( $ query ) {
26+ $ query -> whereNull ( ' stats_last_collected_at ' )
27+ -> orWhere ('stats_last_collected_at ' , ' < ' , now ()-> subDay ());
28+ })
29+ -> where ( ' is_blocked ' , false )
3030 ->limit (250 )
31- ->lazyById ()
32- ->each (function ($ instance ) use (&$ count , $ now ) {
33- $ instance ->user_count = Profile::whereDomain ($ instance ->domain )->count ();
34- $ instance ->video_count = Video::join ('profiles ' , 'videos.profile_id ' , '= ' , 'profiles.id ' )
35- ->where ('profiles.domain ' , $ instance ->domain )
36- ->count ();
37- $ instance ->comment_count = Comment::join ('profiles ' , 'comments.profile_id ' , '= ' , 'profiles.id ' )
38- ->where ('profiles.domain ' , $ instance ->domain )
39- ->count ();
40- $ instance ->reply_count = CommentReply::join ('profiles ' , 'comment_replies.profile_id ' , '= ' , 'profiles.id ' )
41- ->where ('profiles.domain ' , $ instance ->domain )
42- ->count ();
43- $ instance ->follower_count = Follower::join ('profiles ' , 'followers.following_id ' , '= ' , 'profiles.id ' )
44- ->where ('profiles.domain ' , $ instance ->domain )
45- ->count ();
46- $ instance ->following_count = Follower::join ('profiles ' , 'followers.profile_id ' , '= ' , 'profiles.id ' )
47- ->where ('profiles.domain ' , $ instance ->domain )
48- ->count ();
49- $ instance ->report_count = Report::join ('profiles ' , 'reports.reported_profile_id ' , '= ' , 'profiles.id ' )
50- ->where ('profiles.domain ' , $ instance ->domain )
51- ->count ();
52- $ instance ->stats_last_collected_at = $ now ;
53- $ instance ->save ();
54-
55- $ count ++;
56- });
31+ ->get ();
32+
33+ foreach ($ instances as $ instance ) {
34+ $ instance ->user_count = Profile::whereDomain ($ instance ->domain )->count ();
35+ $ instance ->video_count = Video::join ('profiles ' , 'videos.profile_id ' , '= ' , 'profiles.id ' )
36+ ->where ('profiles.domain ' , $ instance ->domain )
37+ ->count ();
38+ $ instance ->comment_count = Comment::join ('profiles ' , 'comments.profile_id ' , '= ' , 'profiles.id ' )
39+ ->where ('profiles.domain ' , $ instance ->domain )
40+ ->count ();
41+ $ instance ->reply_count = CommentReply::join ('profiles ' , 'comment_replies.profile_id ' , '= ' , 'profiles.id ' )
42+ ->where ('profiles.domain ' , $ instance ->domain )
43+ ->count ();
44+ $ instance ->follower_count = Follower::join ('profiles ' , 'followers.following_id ' , '= ' , 'profiles.id ' )
45+ ->where ('profiles.domain ' , $ instance ->domain )
46+ ->count ();
47+ $ instance ->following_count = Follower::join ('profiles ' , 'followers.profile_id ' , '= ' , 'profiles.id ' )
48+ ->where ('profiles.domain ' , $ instance ->domain )
49+ ->count ();
50+ $ instance ->report_count = Report::join ('profiles ' , 'reports.reported_profile_id ' , '= ' , 'profiles.id ' )
51+ ->where ('profiles.domain ' , $ instance ->domain )
52+ ->count ();
53+ $ instance ->stats_last_collected_at = $ now ;
54+ $ instance ->save ();
55+
56+ $ count ++;
57+ }
5758
5859 $ this ->info ("Collected stats for {$ count } instances " );
5960 }
0 commit comments