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

Ranking Mechanism and Listing Retrievals (depreciated)

Mark Hester edited this page Jun 8, 2019 · 1 revision

Overview

Our platform provides performance enhancing features that allow an increase of speed for listings presented on the front page and card profiles.

There is two mechanisms in place to ensure effective speed consistently.

Database Retrieval

All listings and information are pulled from the database EXCEPT voting and clicking counters, points or ranks. Listings with their relationships can be retrieved using Listing::relations()

Redis Caching

Redis caching is used to store a table of all rankings that listings can have, this is prone to changes as more votes are made, and rather than counting is incremented, allowing dynamic count changes on votes and clicks, this pulls the initial table to build the cache from the mySQL view table named listing_ranks using the below code. This code is currently tested at 200,000 and 300 listings at 94ms time, however this is just to build the cache.

SELECT id as listing_id, (@rank:=@rank + 1) AS rank, (( SELECT count(*) FROM votes WHERE listings.id = votes.listing_id AND created_at >= DATE(NOW()) - INTERVAL 7 DAY ) * 6) AS "votes", ( SELECT count(*) FROM clicks WHERE listings.id = clicks.listing_id AND created_at >= DATE(NOW()) - INTERVAL 7 DAY ) AS "clicks" FROM listings, (SELECT @rank := 0) init ORDER BY (votes + clicks) desc;

To use the data cached from the view table use app('rankings') which returns a Illuminate\Support\Collection which allows changes to the data in a fluid manner, the ranking entry can then load its relationship counterpart with ranking->listing allowing retrieval of top 10 servers etc..

Listing Collection

The withRanking() provides an interface for logic to exist and be applied to a retrieved collection, allowing logic to apply on partitions of the model rather than whole on each update, this works very similiar to how the ranking view table works, however it allows specific listing collections rather than whole.

Interaction Observers

Interactions on the platform are those that a user can manipulate a listing such as vote, click, review, we observer the vote and click interaction to allow incrementation of the app('rankings') votes_count/clicks_count values in the cache while also using MYSql as a hard interaction copy.