Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
[1.1.13] #232 CertifyRankPosition has been attempted too many times o…
Browse files Browse the repository at this point in the history
…r run too long, corrections to ga on local development, refactor to naming.
  • Loading branch information
marky291 committed Aug 11, 2019
1 parent 49cea98 commit 813ec49
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 94 deletions.
60 changes: 0 additions & 60 deletions app/Listings/CertifyRankPosition.php

This file was deleted.

2 changes: 2 additions & 0 deletions app/Listings/ListingRanking.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Listings;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;

Expand All @@ -13,6 +14,7 @@
* @property int votes
* @property int clicks
* @property int points
* @method static Builder where(string $string, int $param)
*/
class ListingRanking extends Model
{
Expand Down
62 changes: 62 additions & 0 deletions app/Listings/RankPositionComparator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace App\Listings;

use App\Listings\ListingRanking;
use Illuminate\Support\Facades\DB;
use Illuminate\Contracts\Queue\ShouldQueue;

/**
* Class ConfirmRankingPosition.
*/
class RankPositionComparator implements ShouldQueue
{
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle($event): void
{
$this->sortListingPosition($event->listing->ranking);
}

/**
* Recursively upgrade the position if it has more points than the next listing.
*
* @param \App\Listings\ListingRanking $listing
*/
private function sortListingPosition(ListingRanking $listing): void
{
// We dont care if its already rank 1.
if ($listing->rank == 1) {
return;
}

/** @var ListingRanking $compare */
$compare = ListingRanking::where('rank', $listing->rank - 1)->first();


if ($listing->points < $compare->points) {
return;
}

// this shit dont care if you guys have the same points
if ($listing->points == $compare->points) {
return;
}

$swap = $compare->rank;

// first we update the next ranked to the current lower rank
// then we use the swap value to store the next rank to the current.
$compare->update(['rank' => $listing->rank]);

// next we swap the rank back to the new position
$listing->update(['rank' => $swap]);

// we should look around, in case another listing is in front with less points.
$this->sortListingPosition($listing);
}
}
6 changes: 3 additions & 3 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use App\Listings\ListingClickedEvent;
use Illuminate\Support\Facades\Event;
use Illuminate\Auth\Events\Registered;
use App\Listings\CertifyRankPosition;
use App\Listings\RankPositionComparator;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

Expand All @@ -22,10 +22,10 @@ class EventServiceProvider extends ServiceProvider
SendEmailVerificationNotification::class,
],
ListingVotedEvent::class => [
CertifyRankPosition::class,
RankPositionComparator::class,
],
ListingClickedEvent::class => [
CertifyRankPosition::class,
RankPositionComparator::class,
],
];

Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
| and that deployments are loading the correct filesource.
|
*/
'version' => '1.1.12',
'version' => '1.1.13',

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/app.js": "/js/app.js?id=6ebfc190e0d0167c7279",
"/js/app.js": "/js/app.js?id=1efb1644fa6533cb9309",
"/css/app.css": "/css/app.css?id=154aa5a6741058a03501"
}
2 changes: 1 addition & 1 deletion resources/js/components/profile/ProfilePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
return this.slug === 'defaults';
},
incrementVote(count) {
ga('send', 'event', 'Listing', 'voted', this.listing.name);
this.listing.ranking.votes++;
ga('send', 'event', 'Listing', 'voted', this.listing.name);
},
isCurrentPage(page) {
return this.currentPage === page;
Expand Down
50 changes: 24 additions & 26 deletions resources/views/layouts/frame.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,29 @@
</div>

<script src="{{ mix('/js/app.js') }}"></script>
@if (app()->environment('production'))
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-117148224-4', 'auto');
// Replace the following lines with the plugins you want to use.
ga('require', 'eventTracker');
ga('require', 'outboundLinkTracker');
ga('require', 'urlChangeTracker');
// ga('require', 'pageVisibilityTracker');
ga('require', 'impressionTracker');
// ga('require', 'maxScrollTracker');
// ...
ga('send', 'pageview');
</script>
<script async src="https://www.google-analytics.com/analytics.js"></script>
<script async src="https://ragnabox.fra1.digitaloceanspaces.com/assets/autotrack-2.4.1.js"></script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-2280364578236676",
enable_page_level_ads: true
});
</script>
@endif
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-117148224-4', 'auto');
// Replace the following lines with the plugins you want to use.
ga('require', 'eventTracker');
ga('require', 'outboundLinkTracker');
ga('require', 'urlChangeTracker');
// ga('require', 'pageVisibilityTracker');
ga('require', 'impressionTracker');
// ga('require', 'maxScrollTracker');
// ...
ga('send', 'pageview');
</script>
<script async src="https://www.google-analytics.com/analytics.js"></script>
<script async src="https://ragnabox.fra1.digitaloceanspaces.com/assets/autotrack-2.4.1.js"></script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-2280364578236676",
enable_page_level_ads: true
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class CertifyRankPositionTest extends TestCase
class RankPositionComparatorTest extends TestCase
{
use RefreshDatabase;

Expand Down

0 comments on commit 813ec49

Please sign in to comment.