• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

marscoin / martianrepublic / 22677277751

04 Mar 2026 03:53PM UTC coverage: 5.241% (+0.04%) from 5.205%
22677277751

push

github

Lennart Lopin
perf: optimize page load with caching and query improvements

0 of 66 new or added lines in 4 files covered. (0.0%)

1 existing line in 1 file now uncovered.

190 of 3625 relevant lines covered (5.24%)

0.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/Http/Controllers/Citizen/IdentityController.php
1
<?php
2
namespace App\Http\Controllers\Citizen;
3

4
use App\Http\Controllers\Controller;
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\DB;
7
use Illuminate\Support\Facades\Auth;
8
use App\Models\Profile;
9
use App\Models\Feed;
10
use App\Models\User;
11
use App\Models\Proposals;
12
use App\Models\HDWallet;
13
use App\Models\CivicWallet;
14
use App\Models\Citizen;
15
use Illuminate\Support\Facades\View;
16
use App\Includes\jsonRPCClient;
17
use App\Includes\AppHelper;
18
use App\Exceptions\Handler;
19
use Exception;
20
use Carbon\Carbon;
21
use Illuminate\Support\Facades\Cache;
22

23

24
class IdentityController extends Controller
25
{
26

27
        /**
28
         * Setup the layout used by the controller.
29
         *
30
         * @return void
31
         */
32

33
        public function __construct()
×
34
        {
35
        }
×
36

37

38
        //Get all public registrations and display table
39
        //
40
    protected function showAll()
×
41
        {
42
                if (Auth::check()) {
×
43
                        $uid = Auth::user()->id;
×
44
                        $profile = Profile::where('userid', '=', $uid)->first();
×
45
                        $wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
46
                        $citcache = Citizen::where('userid', '=', $uid)->first();
×
47
                        if (!$profile) {
×
48
                                return redirect('/twofa');
×
49
                        } else {
50
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
51
                                        return redirect('/twofachallenge');
×
52
                                }
53
                        }
54
                        $view = View::make('citizen.registry');
×
55
                        $view->wallet_open = $profile->civic_wallet_open;
×
56
                        $view->isCitizen = $profile->citizen;
×
57
                        $view->citcache = $citcache;
×
58
                        $view->isGP  = $profile->general_public;
×
59
                        $view->mePublic = Feed::where('userid', '=', $uid)->where('tag', '=', "GP")->first();
×
60
                        $view->meCitizen = Feed::where('userid', '=', $uid)->where('tag', '=', "CT")->first();
×
61
                        $view->feed = Feed::where('userid', '=', $uid)->whereNotNull('mined')->whereNotIn('tag', ['GP','CT'])->orderBy('created_at', 'desc')->get();
×
62
                        $view->endorsed = array();
×
63
                        
64
                        // Cache registry lists for 5 minutes - these are expensive queries that change infrequently
NEW
65
                        $view->everyPublic = Cache::remember('registry_every_public', 300, function () {
×
NEW
66
                                return DB::select('SELECT u.*, p.*, c.*, ( SELECT f.txid FROM feed f WHERE f.userid = u.id AND f.tag = ? ORDER BY f.id DESC LIMIT 1) AS txid, ( SELECT f.mined FROM feed f WHERE f.userid = u.id AND f.tag = ? ORDER BY f.id DESC LIMIT 1) AS mined FROM users u JOIN profile p ON u.id = p.userid JOIN citizen c ON u.id = c.userid WHERE EXISTS ( SELECT 1 FROM feed f WHERE f.userid = u.id AND f.tag = ?) AND u.id NOT IN (?, ?) ORDER BY mined DESC', ['GP', 'GP', 'GP', 6462, 7601]);
×
NEW
67
                        });
×
68

NEW
69
                        $view->everyCitizen = Cache::remember('registry_every_citizen', 300, function () {
×
NEW
70
                                return DB::select('SELECT u.*, p.*, c.*, ( SELECT f.txid FROM feed f WHERE f.userid = u.id AND f.tag = ? ORDER BY f.id DESC LIMIT 1 ) AS txid, ( SELECT f.mined FROM feed f WHERE f.userid = u.id AND f.tag = ? ORDER BY f.id DESC LIMIT 1 ) AS mined FROM users u JOIN profile p ON u.id = p.userid JOIN citizen c ON u.id = c.userid WHERE EXISTS ( SELECT 1 FROM feed f WHERE f.userid = u.id AND f.tag = ? ) AND u.id NOT IN (?) ORDER BY mined DESC', ['CT', 'CT', 'CT', 6462]);
×
NEW
71
                        });
×
72

NEW
73
                        $view->everyApplicant = Cache::remember('registry_every_applicant', 300, function () {
×
NEW
74
                                return DB::select('SELECT profile.userid, users.fullname, citizen.*, civic_wallet.public_addr AS address FROM users, profile, civic_wallet, citizen WHERE profile.userid = users.id AND users.id = civic_wallet.user_id AND citizen.userid = users.id AND profile.has_application = ? AND users.id NOT IN (?)', [1, 6462]);
×
NEW
75
                        });
×
76
                        
77
                        $view->recentActivityCount = Feed::where('userid', $uid)->where('mined', '>=', Carbon::now()->subDay())->count();
×
78

79
                        if ($wallet) {
×
80
                                $view->balance = 0;
×
81
                                $view->public_address = $wallet['public_addr'];
×
82
                                $view->endorsed = Feed::where('message', '=', $wallet['public_addr'])->where('tag', '=', "ED")->get();
×
83
                        } else {
84
                                $view->balance = 0;
×
85
                                $view->public_address = "";
×
86
                        }
87

88
                        return $view;
×
89

90

91
                }else{
92
            return redirect('/login');
×
93
        }
94

95
                
96
        }
97

98

99

100
        protected function printout()
×
101
        {
102
                if (Auth::check()) {
×
103
                        $uid = Auth::user()->id;
×
104
                        $profile = Profile::where('userid', '=', $uid)->first();
×
105
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
106
                        $view = View::make('citizen.printout');
×
107
                        $citcache = Citizen::where('userid', '=', $uid)->first();
×
108
                        $view->fullname = $citcache->firstname . " " . $citcache->lastname;
×
109
                        
110
                        if ($civic_wallet) {
×
111
                                $view->public_address = $civic_wallet['public_addr'];
×
112
                        } else {
113
                                $view->balance = 0;
×
114
                                $view->public_address = "";
×
115
                        }
116
                        return $view;
×
117
                }else{
118
            return redirect('/login');
×
119
        }
120
        }
121

122

123
        protected function printout2()
×
124
        {
125
                if (Auth::check()) {
×
126
                        $uid = Auth::user()->id;
×
127
                        $profile = Profile::where('userid', '=', $uid)->first();
×
128
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
129
                        $view = View::make('citizen.themes.printout2');
×
130
                        $citcache = Citizen::where('userid', '=', $uid)->first();
×
131
                        $view->fullname = $citcache->firstname . " " . $citcache->lastname;
×
132
                        
133
                        if ($civic_wallet) {
×
134
                                $view->public_address = $civic_wallet['public_addr'];
×
135
                        } else {
136
                                $view->balance = 0;
×
137
                                $view->public_address = "";
×
138
                        }
139
                        return $view;
×
140
                }else{
141
            return redirect('/login');
×
142
        }
143
        }
144

145

146

147
        protected function printout3()
×
148
        {
149
                if (Auth::check()) {
×
150
                        $uid = Auth::user()->id;
×
151
                        $profile = Profile::where('userid', '=', $uid)->first();
×
152
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
153
                        $view = View::make('citizen.themes.printout3');
×
154
                        $citcache = Citizen::where('userid', '=', $uid)->first();
×
155
                        $view->fullname = $citcache->firstname . " " . $citcache->lastname;
×
156
                        
157
                        if ($civic_wallet) {
×
158
                                $view->public_address = $civic_wallet['public_addr'];
×
159
                        } else {
160
                                $view->balance = 0;
×
161
                                $view->public_address = "";
×
162
                        }
163
                        return $view;
×
164
                }else{
165
            return redirect('/login');
×
166
        }
167
        }
168

169

170

171

172
        //Get profile view of another Martian Citizen
173
        //
174
    protected function showId($address)
×
175
        {
176
                
177
                if (Auth::check()) {
×
178
                        $uid = Auth::user()->id;
×
179
                        //Martian user we are looking at
180
                        $martian = Citizen::where('public_address', '=', $address)->first();
×
181
                        $martian_profile = Profile::where('userid', '=', $martian->userid)->first();
×
182
                        $martian_proposals = Proposals::where('user_id', '=', $martian->userid)->count();
×
183
                        $myprofile = Profile::where('userid', '=', $uid)->first();
×
184

185
                        if (!$myprofile) {
×
186
                                return redirect('/twofa');
×
187
                        } else {
188
                                if ($myprofile->openchallenge == 1 || is_null($myprofile->openchallenge)) {
×
189
                                        return redirect('/twofachallenge');
×
190
                                }
191
                        }
192
                        $view = View::make('citizen.martian');
×
193
                        $view->wallet_open = $myprofile->civic_wallet_open;
×
194

195

196
                        $view->isCitizen = $martian_profile->citizen;
×
197
                        $view->endorsements = $martian_profile->endorse_cnt;
×
198
                        $view->proposals = $martian_proposals;
×
199
                        $view->isGP  = $martian_profile->general_public;
×
200
                        $view->mePublic = Feed::where('userid', '=', $martian->userid)->where('tag', '=', "GP")->first();
×
201
                        $view->meCitizen = Feed::where('userid', '=', $martian->userid)->where('tag', '=', "CT")->first();
×
202
                        $view->endorsed = Feed::where('userid', '=', $martian->userid)->where('tag', '=', "ED")->count();
×
203

204

205
                        $view->citcache = $martian;
×
206

207
                        return $view;
×
208

209

210
                }else{
211
            return redirect('/login');
×
212
        }
213

214
                
215
        }
216

217

218

219
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc