We’re gonna build a great cache, and make PostgreSQL pay for it

class AddRanksView extends Migration
{

public function up()
{
DB::statement("CREATE MATERIALIZED VIEW ranks AS
SELECT *,
rank() over (partition by leaderboard_id order by score desc)
FROM throne_scores
WHERE is_hidden = false");
}
public function down()
{
DB::statement("DROP MATERIALIZED VIEW ranks");
}
}
use DB;class UpdateRanks extends Command
{
// ...
public function handle()
{
DB::statement("REFRESH MATERIALIZED VIEW ranks");
}
}
Difference in application responsiveness. Dashed: yesterday’s data (before implementing the cache). Solid: today’s data (after implementing the cache).

--

--

a chaotic neutral with an anime avatar

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store