-
Notifications
You must be signed in to change notification settings - Fork 0
Ranking Mechanism and Listing Retrievals (depreciated)
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.
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 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..
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.
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.