From 9f928ae570a2b4cc5de9791e6a2d58a2b279f0ab Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 00:31:30 -0600 Subject: [PATCH 1/9] Update LikeController --- app/Http/Controllers/LikeController.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/LikeController.php b/app/Http/Controllers/LikeController.php index 2b87353d..ef4ab26e 100644 --- a/app/Http/Controllers/LikeController.php +++ b/app/Http/Controllers/LikeController.php @@ -32,20 +32,23 @@ class LikeController extends Controller $like = Like::whereProfileId($profile->id)->whereStatusId($status->id)->firstOrFail(); $like->forceDelete(); $count--; + if($count >= 0) { + $status->likes_count = $count; + $status->save(); + } } else { $like = new Like(); $like->profile_id = $profile->id; $like->status_id = $status->id; $like->save(); $count++; + if($count >= 0) { + $status->likes_count = $count; + $status->save(); + } LikePipeline::dispatch($like); } - $likes = Like::whereProfileId($profile->id) - ->orderBy('id', 'desc') - ->take(1000) - ->pluck('status_id'); - if ($request->ajax()) { $response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count]; } else { From 84e01f1132fcbeeab1fb1cc1490ecf61b14ca39e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 00:47:38 -0600 Subject: [PATCH 2/9] Update StatusController --- app/Http/Controllers/StatusController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index fe2ac646..1f3c119a 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -259,7 +259,12 @@ class StatusController extends Controller $count++; SharePipeline::dispatch($share); } - + + if($count >= 0) { + $status->reblogs_count = $count; + $status->save(); + } + if ($request->ajax()) { $response = ['code' => 200, 'msg' => 'Share saved', 'count' => $count]; } else { From bed5cc74dee312c77e8212e9e53d90b2fda33144 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 00:47:57 -0600 Subject: [PATCH 3/9] Update LikeController --- app/Http/Controllers/LikeController.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/LikeController.php b/app/Http/Controllers/LikeController.php index ef4ab26e..08e0a421 100644 --- a/app/Http/Controllers/LikeController.php +++ b/app/Http/Controllers/LikeController.php @@ -20,10 +20,11 @@ class LikeController extends Controller public function store(Request $request) { $this->validate($request, [ - 'item' => 'required|integer|min:1', - ]); + 'item' => 'required|integer|min:1', + ]); - $profile = Auth::user()->profile; + $user = Auth::user(); + $profile = $user->profile; $status = Status::withCount('likes')->findOrFail($request->input('item')); $count = $status->likes_count; @@ -49,6 +50,8 @@ class LikeController extends Controller LikePipeline::dispatch($like); } + Cache::forget('status:'.$status->id.':likedby:userid:'.$user->id); + if ($request->ajax()) { $response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count]; } else { From f98c7caff6258f33c80c1f55691d946ee7a3f8da Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 00:48:40 -0600 Subject: [PATCH 4/9] Update Status model --- app/Status.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Status.php b/app/Status.php index f29e88e0..2e2470e6 100644 --- a/app/Status.php +++ b/app/Status.php @@ -150,8 +150,10 @@ class Status extends Model if(Auth::check() == false) { return false; } - $profile = Auth::user()->profile; - return Like::whereProfileId($profile->id)->whereStatusId($this->id)->count(); + return Cache::remember('status:'.$this->id.':likedby:userid:'.Auth::id(), now()->addHours(30), function() { + $profile = Auth::user()->profile; + return Like::whereProfileId($profile->id)->whereStatusId($this->id)->count(); + }); } public function likedBy() From 5204aa2c1c693568f76ffcceb77129f8550130d7 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 01:01:36 -0600 Subject: [PATCH 5/9] Update Api StatusTransformer --- app/Transformer/Api/StatusTransformer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Transformer/Api/StatusTransformer.php b/app/Transformer/Api/StatusTransformer.php index c74f4ed6..1c033c1f 100644 --- a/app/Transformer/Api/StatusTransformer.php +++ b/app/Transformer/Api/StatusTransformer.php @@ -27,8 +27,8 @@ class StatusTransformer extends Fractal\TransformerAbstract 'content' => $status->rendered ?? $status->caption, 'created_at' => $status->created_at->format('c'), 'emojis' => [], - 'reblogs_count' => $status->shares()->count(), - 'favourites_count' => $status->likes()->count(), + 'reblogs_count' => $status->reblogs_count != 0 ? $status->reblogs_count: $status->shares()->count(), + 'favourites_count' => $status->likes_count != 0 ? $status->likes_count: $status->likes()->count(), 'reblogged' => $status->shared(), 'favourited' => $status->liked(), 'muted' => null, @@ -47,7 +47,7 @@ class StatusTransformer extends Fractal\TransformerAbstract 'comments_disabled' => $status->comments_disabled ? true : false, 'thread' => false, 'replies' => [], - 'parent' => $status->parent() ? $this->transform($status->parent()) : [], + 'parent' => [], ]; } From 4f25c73d59b7896de0d34b9a22339c162750d520 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 01:06:22 -0600 Subject: [PATCH 6/9] Update Activity.vue --- resources/assets/js/components/Activity.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/assets/js/components/Activity.vue b/resources/assets/js/components/Activity.vue index 3bcdac29..c237ee61 100644 --- a/resources/assets/js/components/Activity.vue +++ b/resources/assets/js/components/Activity.vue @@ -225,6 +225,7 @@ export default { break; case 'like': case 'favourite': + case 'comment': return n.status.url; break; } From e98107fd5e409f93c73e81d422a5b1cea4a37ad8 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 01:07:21 -0600 Subject: [PATCH 7/9] Update compiled assets --- public/js/activity.js | 2 +- public/mix-manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/js/activity.js b/public/js/activity.js index 7c8a688c..6952e855 100644 --- a/public/js/activity.js +++ b/public/js/activity.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[2],{1:function(t,a,e){t.exports=e("hUgz")},"KHd+":function(t,a,e){"use strict";function n(t,a,e,n,o,i,s,r){var c,l="function"==typeof t?t.options:t;if(a&&(l.render=a,l.staticRenderFns=e,l._compiled=!0),n&&(l.functional=!0),i&&(l._scopeId="data-v-"+i),s?(c=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),o&&o.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(s)},l._ssrRegister=c):o&&(c=r?function(){o.call(this,this.$root.$options.shadowRoot)}:o),c)if(l.functional){l._injectStyles=c;var u=l.render;l.render=function(t,a){return c.call(a),u(t,a)}}else{var d=l.beforeCreate;l.beforeCreate=d?[].concat(d,c):[c]}return{exports:t,options:l}}e.d(a,"a",function(){return n})},hUgz:function(t,a,e){Vue.component("activity-component",e("tXHz").default)},tXHz:function(t,a,e){"use strict";e.r(a);function n(t){return function(t){if(Array.isArray(t)){for(var a=0,e=new Array(t.length);a10?t.complete():axios.get("/api/v1/notifications",{params:{page:this.notificationCursor}}).then(function(e){if(e.data.length){var o,i=e.data.filter(function(t){return!("share"==t.type&&!status)});(o=a.notifications).push.apply(o,n(i)),a.notificationCursor++,t.loaded()}else t.complete()})},truncate:function(t){return t.length<=15?t:t.slice(0,15)+"..."},timeAgo:function(t){var a=Date.parse(t),e=Math.floor((new Date-a)/1e3),n=Math.floor(e/31536e3);return n>=1?n+"y":(n=Math.floor(e/604800))>=1?n+"w":(n=Math.floor(e/86400))>=1?n+"d":(n=Math.floor(e/3600))>=1?n+"h":(n=Math.floor(e/60))>=1?n+"m":Math.floor(e)+"s"},mentionUrl:function(t){return"/p/"+t.account.username+"/"+t.id},followProfile:function(t){var a=this,e=t.account.id;axios.post("/i/follow",{item:e}).then(function(t){a.notifications.map(function(t){t.account.id===e&&(t.relationship.following=!0)})}).catch(function(t){t.response.data.message&&swal("Error",t.response.data.message,"error")})},viewContext:function(t){switch(t.type){case"follow":return t.account.url;case"mention":return t.status.url;case"like":case"favourite":return t.status.url}return"/"}}},i=e("KHd+"),s=Object(i.a)(o,function(){var t=this,a=t.$createElement,e=t._self._c||a;return e("div",[e("div",{staticClass:"container"},[e("div",{staticClass:"row my-5"},[e("div",{staticClass:"col-12 col-md-8 offset-md-2"},[t._l(t.notifications,function(a,n){return t.notifications.length>0?e("div",{staticClass:"media mb-3 align-items-center px-3 border-bottom pb-3"},[e("img",{staticClass:"mr-2 rounded-circle",staticStyle:{border:"1px solid #ccc"},attrs:{src:a.account.avatar,alt:"",width:"32px",height:"32px"}}),t._v(" "),e("div",{staticClass:"media-body font-weight-light"},["favourite"==a.type?e("div",[e("p",{staticClass:"my-0"},[e("a",{staticClass:"font-weight-bold text-dark word-break",attrs:{href:a.account.url,"data-placement":"bottom","data-toggle":"tooltip",title:a.account.username}},[t._v(t._s(t.truncate(a.account.username)))]),t._v(" liked your "),e("a",{staticClass:"font-weight-bold",attrs:{href:a.status.url}},[t._v("post")]),t._v(".\n\t\t\t\t\t\t\t")])]):"comment"==a.type?e("div",[e("p",{staticClass:"my-0"},[e("a",{staticClass:"font-weight-bold text-dark word-break",attrs:{href:a.account.url,"data-placement":"bottom","data-toggle":"tooltip",title:a.account.username}},[t._v(t._s(t.truncate(a.account.username)))]),t._v(" commented on your "),e("a",{staticClass:"font-weight-bold",attrs:{href:a.status.url}},[t._v("post")]),t._v(".\n\t\t\t\t\t\t\t")])]):"mention"==a.type?e("div",[e("p",{staticClass:"my-0"},[e("a",{staticClass:"font-weight-bold text-dark word-break",attrs:{href:a.account.url,"data-placement":"bottom","data-toggle":"tooltip",title:a.account.username}},[t._v(t._s(t.truncate(a.account.username)))]),t._v(" "),e("a",{staticClass:"font-weight-bold",attrs:{href:t.mentionUrl(a.status)}},[t._v("mentioned")]),t._v(" you.\n\t\t\t\t\t\t\t")])]):"follow"==a.type?e("div",[e("p",{staticClass:"my-0"},[e("a",{staticClass:"font-weight-bold text-dark word-break",attrs:{href:a.account.url,"data-placement":"bottom","data-toggle":"tooltip",title:a.account.username}},[t._v(t._s(t.truncate(a.account.username)))]),t._v(" followed you.\n\t\t\t\t\t\t\t")])]):"share"==a.type?e("div",[e("p",{staticClass:"my-0"},[e("a",{staticClass:"font-weight-bold text-dark word-break",attrs:{href:a.account.url,"data-placement":"bottom","data-toggle":"tooltip",title:a.account.username}},[t._v(t._s(t.truncate(a.account.username)))]),t._v(" shared your "),e("a",{staticClass:"font-weight-bold",attrs:{href:a.status.reblog.url}},[t._v("post")]),t._v(".\n\t\t\t\t\t\t\t")])]):t._e(),t._v(" "),e("div",{staticClass:"align-items-center"},[e("span",{staticClass:"small text-muted",attrs:{"data-toggle":"tooltip","data-placement":"bottom",title:a.created_at}},[t._v(t._s(t.timeAgo(a.created_at)))])])]),t._v(" "),e("div",[a.status&&a.status&&a.status.media_attachments&&a.status.media_attachments.length?e("div",[e("a",{attrs:{href:a.status.url}},[e("img",{attrs:{src:a.status.media_attachments[0].preview_url,width:"32px",height:"32px"}})])]):a.status&&a.status.parent&&a.status.parent.media_attachments&&a.status.parent.media_attachments.length?e("div",[e("a",{attrs:{href:a.status.parent.url}},[e("img",{attrs:{src:a.status.parent.media_attachments[0].preview_url,width:"32px",height:"32px"}})])]):e("div",[e("a",{staticClass:"btn btn-outline-primary py-0 font-weight-bold",attrs:{href:t.viewContext(a)}},[t._v("View")])])])]):t._e()}),t._v(" "),t.notifications.length?e("div",[e("infinite-loading",{on:{infinite:t.infiniteNotifications}},[e("div",{staticClass:"font-weight-bold",attrs:{slot:"no-results"},slot:"no-results"}),t._v(" "),e("div",{staticClass:"font-weight-bold",attrs:{slot:"no-more"},slot:"no-more"})])],1):t._e(),t._v(" "),0==t.notifications.length?e("div",{staticClass:"text-lighter text-center py-3"},[t._m(0),t._v(" "),e("p",{staticClass:"mb-0 small font-weight-bold"},[t._v("0 Notifications!")])]):t._e()],2)])])])},[function(){var t=this.$createElement,a=this._self._c||t;return a("p",{staticClass:"mb-0"},[a("i",{staticClass:"fas fa-inbox fa-3x"})])}],!1,null,null,null);a.default=s.exports}},[[1,0]]]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[2],{1:function(t,a,e){t.exports=e("hUgz")},"KHd+":function(t,a,e){"use strict";function n(t,a,e,n,o,i,s,r){var c,l="function"==typeof t?t.options:t;if(a&&(l.render=a,l.staticRenderFns=e,l._compiled=!0),n&&(l.functional=!0),i&&(l._scopeId="data-v-"+i),s?(c=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),o&&o.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(s)},l._ssrRegister=c):o&&(c=r?function(){o.call(this,this.$root.$options.shadowRoot)}:o),c)if(l.functional){l._injectStyles=c;var u=l.render;l.render=function(t,a){return c.call(a),u(t,a)}}else{var d=l.beforeCreate;l.beforeCreate=d?[].concat(d,c):[c]}return{exports:t,options:l}}e.d(a,"a",function(){return n})},hUgz:function(t,a,e){Vue.component("activity-component",e("tXHz").default)},tXHz:function(t,a,e){"use strict";e.r(a);function n(t){return function(t){if(Array.isArray(t)){for(var a=0,e=new Array(t.length);a10?t.complete():axios.get("/api/v1/notifications",{params:{page:this.notificationCursor}}).then(function(e){if(e.data.length){var o,i=e.data.filter(function(t){return!("share"==t.type&&!status)});(o=a.notifications).push.apply(o,n(i)),a.notificationCursor++,t.loaded()}else t.complete()})},truncate:function(t){return t.length<=15?t:t.slice(0,15)+"..."},timeAgo:function(t){var a=Date.parse(t),e=Math.floor((new Date-a)/1e3),n=Math.floor(e/31536e3);return n>=1?n+"y":(n=Math.floor(e/604800))>=1?n+"w":(n=Math.floor(e/86400))>=1?n+"d":(n=Math.floor(e/3600))>=1?n+"h":(n=Math.floor(e/60))>=1?n+"m":Math.floor(e)+"s"},mentionUrl:function(t){return"/p/"+t.account.username+"/"+t.id},followProfile:function(t){var a=this,e=t.account.id;axios.post("/i/follow",{item:e}).then(function(t){a.notifications.map(function(t){t.account.id===e&&(t.relationship.following=!0)})}).catch(function(t){t.response.data.message&&swal("Error",t.response.data.message,"error")})},viewContext:function(t){switch(t.type){case"follow":return t.account.url;case"mention":return t.status.url;case"like":case"favourite":case"comment":return t.status.url}return"/"}}},i=e("KHd+"),s=Object(i.a)(o,function(){var t=this,a=t.$createElement,e=t._self._c||a;return e("div",[e("div",{staticClass:"container"},[e("div",{staticClass:"row my-5"},[e("div",{staticClass:"col-12 col-md-8 offset-md-2"},[t._l(t.notifications,function(a,n){return t.notifications.length>0?e("div",{staticClass:"media mb-3 align-items-center px-3 border-bottom pb-3"},[e("img",{staticClass:"mr-2 rounded-circle",staticStyle:{border:"1px solid #ccc"},attrs:{src:a.account.avatar,alt:"",width:"32px",height:"32px"}}),t._v(" "),e("div",{staticClass:"media-body font-weight-light"},["favourite"==a.type?e("div",[e("p",{staticClass:"my-0"},[e("a",{staticClass:"font-weight-bold text-dark word-break",attrs:{href:a.account.url,"data-placement":"bottom","data-toggle":"tooltip",title:a.account.username}},[t._v(t._s(t.truncate(a.account.username)))]),t._v(" liked your "),e("a",{staticClass:"font-weight-bold",attrs:{href:a.status.url}},[t._v("post")]),t._v(".\n\t\t\t\t\t\t\t")])]):"comment"==a.type?e("div",[e("p",{staticClass:"my-0"},[e("a",{staticClass:"font-weight-bold text-dark word-break",attrs:{href:a.account.url,"data-placement":"bottom","data-toggle":"tooltip",title:a.account.username}},[t._v(t._s(t.truncate(a.account.username)))]),t._v(" commented on your "),e("a",{staticClass:"font-weight-bold",attrs:{href:a.status.url}},[t._v("post")]),t._v(".\n\t\t\t\t\t\t\t")])]):"mention"==a.type?e("div",[e("p",{staticClass:"my-0"},[e("a",{staticClass:"font-weight-bold text-dark word-break",attrs:{href:a.account.url,"data-placement":"bottom","data-toggle":"tooltip",title:a.account.username}},[t._v(t._s(t.truncate(a.account.username)))]),t._v(" "),e("a",{staticClass:"font-weight-bold",attrs:{href:t.mentionUrl(a.status)}},[t._v("mentioned")]),t._v(" you.\n\t\t\t\t\t\t\t")])]):"follow"==a.type?e("div",[e("p",{staticClass:"my-0"},[e("a",{staticClass:"font-weight-bold text-dark word-break",attrs:{href:a.account.url,"data-placement":"bottom","data-toggle":"tooltip",title:a.account.username}},[t._v(t._s(t.truncate(a.account.username)))]),t._v(" followed you.\n\t\t\t\t\t\t\t")])]):"share"==a.type?e("div",[e("p",{staticClass:"my-0"},[e("a",{staticClass:"font-weight-bold text-dark word-break",attrs:{href:a.account.url,"data-placement":"bottom","data-toggle":"tooltip",title:a.account.username}},[t._v(t._s(t.truncate(a.account.username)))]),t._v(" shared your "),e("a",{staticClass:"font-weight-bold",attrs:{href:a.status.reblog.url}},[t._v("post")]),t._v(".\n\t\t\t\t\t\t\t")])]):t._e(),t._v(" "),e("div",{staticClass:"align-items-center"},[e("span",{staticClass:"small text-muted",attrs:{"data-toggle":"tooltip","data-placement":"bottom",title:a.created_at}},[t._v(t._s(t.timeAgo(a.created_at)))])])]),t._v(" "),e("div",[a.status&&a.status&&a.status.media_attachments&&a.status.media_attachments.length?e("div",[e("a",{attrs:{href:a.status.url}},[e("img",{attrs:{src:a.status.media_attachments[0].preview_url,width:"32px",height:"32px"}})])]):a.status&&a.status.parent&&a.status.parent.media_attachments&&a.status.parent.media_attachments.length?e("div",[e("a",{attrs:{href:a.status.parent.url}},[e("img",{attrs:{src:a.status.parent.media_attachments[0].preview_url,width:"32px",height:"32px"}})])]):e("div",[e("a",{staticClass:"btn btn-outline-primary py-0 font-weight-bold",attrs:{href:t.viewContext(a)}},[t._v("View")])])])]):t._e()}),t._v(" "),t.notifications.length?e("div",[e("infinite-loading",{on:{infinite:t.infiniteNotifications}},[e("div",{staticClass:"font-weight-bold",attrs:{slot:"no-results"},slot:"no-results"}),t._v(" "),e("div",{staticClass:"font-weight-bold",attrs:{slot:"no-more"},slot:"no-more"})])],1):t._e(),t._v(" "),0==t.notifications.length?e("div",{staticClass:"text-lighter text-center py-3"},[t._m(0),t._v(" "),e("p",{staticClass:"mb-0 small font-weight-bold"},[t._v("0 Notifications!")])]):t._e()],2)])])])},[function(){var t=this.$createElement,a=this._self._c||t;return a("p",{staticClass:"mb-0"},[a("i",{staticClass:"fas fa-inbox fa-3x"})])}],!1,null,null,null);a.default=s.exports}},[[1,0]]]); \ No newline at end of file diff --git a/public/mix-manifest.json b/public/mix-manifest.json index c92679d4..a6851bc8 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,7 +1,7 @@ { "/js/manifest.js": "/js/manifest.js?id=01c8731923a46c30aaed", "/js/vendor.js": "/js/vendor.js?id=cb03d3c4fd7d4093f5b1", - "/js/activity.js": "/js/activity.js?id=988d3df8e9dc2d16a43c", + "/js/activity.js": "/js/activity.js?id=e9d373d06150ccd77557", "/js/app.js": "/js/app.js?id=025bc09bbc4e2d1898e3", "/css/app.css": "/css/app.css?id=461b8782fc167f734ffa", "/css/appdark.css": "/css/appdark.css?id=34cd81dd9c8bc68cfd51", From 7d7a64382b24d27efd0f6801b56a8ab6c29a361b Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 01:15:47 -0600 Subject: [PATCH 8/9] Update Status model --- app/Status.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Status.php b/app/Status.php index 2e2470e6..769f0c71 100644 --- a/app/Status.php +++ b/app/Status.php @@ -150,9 +150,11 @@ class Status extends Model if(Auth::check() == false) { return false; } - return Cache::remember('status:'.$this->id.':likedby:userid:'.Auth::id(), now()->addHours(30), function() { - $profile = Auth::user()->profile; - return Like::whereProfileId($profile->id)->whereStatusId($this->id)->count(); + $user = Auth::user(); + $id = $this->id; + return Cache::remember('status:'.$this->id.':likedby:userid:'.$user->id, now()->addHours(30), function() use($user, $id) { + $profile = $user->profile; + return Like::whereProfileId($profile->id)->whereStatusId($id)->count(); }); } @@ -193,9 +195,12 @@ class Status extends Model if(Auth::check() == false) { return false; } - $profile = Auth::user()->profile; - - return self::whereProfileId($profile->id)->whereReblogOfId($this->id)->count(); + $user = Auth::user(); + $id = $this->id; + return Cache::remember('status:'.$this->id.':sharedby:userid:'.$user->id, now()->addHours(30), function() use($user, $id) { + $profile = $user->profile; + return self::whereProfileId($profile->id)->whereReblogOfId($id)->count(); + }); } public function sharedBy() From 6095f4c9c713557c5ccc22c2699b796e6b4b9fda Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 01:16:10 -0600 Subject: [PATCH 9/9] Update StatusController --- app/Http/Controllers/StatusController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 1f3c119a..136c3ba5 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -234,7 +234,8 @@ class StatusController extends Controller 'item' => 'required|integer|min:1', ]); - $profile = Auth::user()->profile; + $user = Auth::user(); + $profile = $user->profile; $status = Status::withCount('shares')->findOrFail($request->input('item')); $count = $status->shares_count; @@ -265,6 +266,8 @@ class StatusController extends Controller $status->save(); } + Cache::forget('status:'.$status->id.':sharedby:userid:'.$user->id); + if ($request->ajax()) { $response = ['code' => 200, 'msg' => 'Share saved', 'count' => $count]; } else {