Skip to content

Instantly share code, notes, and snippets.

@drsnyder
drsnyder / object-ordering-setup.sql
Last active August 29, 2015 13:56
This gist contains setup SQL and example data for reproducing an object ordering problem that I'm trying to optimize.
-- For normal_rand() so we can create distributions that are not uniform.
-- The "real" distributions are not normal but they are closer to normal than uniform.
CREATE EXTENSION tablefunc;
BEGIN;
-- ###########################
-- The base "object" that is displayed using different either id DESC proxy
-- or scores.
CREATE TABLE objects (
id INTEGER PRIMARY KEY,
@drsnyder
drsnyder / array-unest-solution.sql
Last active August 29, 2015 13:56
A possible solution to the object ordering problem described here https://gist.github.com/drsnyder/9277054.
-- One solution to the problem. Cache the ordering in an array.
-- Pros:
-- It's fast enough (~90ms) even with filtering
-- Updates are atomic. You are only updating one row in one table.
-- If the ordering is predictable (e.g. create time) then the
-- maintenance is fast and easy because you just append to the array.
-- Cons:
-- It requires maintenance. It's not a view and it's not a relation
-- in the formal sense (is that right?). CREATE TYPE object_container_order_type AS (
-- Another solution using a rollup table.
CREATE TABLE object_container_order_rollup (
container_id INTEGER REFERENCES containers(id),
category_id INTEGER REFERENCES categories(id),
object_id INTEGER REFERENCES objects(id),
type VARCHAR(32) NOT NULL,
index INTEGER NOT NULL,
PRIMARY KEY (container_id, type, category_id, object_id)
);
{
"sections": [
{
"title": "Hitman Absolution Full Disclosure Trailer",
"level": 1,
"content": [],
"images": []
},
{
"title": "Description",
{
"items": {
"19192": {
"id": 19192,
"title": "Hitman Absolution Full Disclosure Trailer",
"ns": 6,
"url": "/File:Hitman_Absolution_Full_Disclosure_Trailer",
"revision": {
"id": 37872,
"user": "TheBlueRogue",
<?php
class FooBar { }
$fooBar = new FooBar();
$iterations = 1e6;
$assignment = false;
$start = microtime(true);
{
"items": {
"19192": {
"id": 19192,
"title": "Hitman Absolution Full Disclosure Trailer",
"ns": 6,
"url": "/File:Hitman_Absolution_Full_Disclosure_Trailer",
"revision": {
"id": 37872,
"user": "TheBlueRogue",
<link href="http://api-public.netflix.com/catalog/titles/series/70023522/cast" rel="http://schemas.netflix.com/catalog/people" title="cast">
<cast>
<link href="http://api-public.netflix.com/catalog/people/30011713" rel="http://schemas.netflix.com/catalog/person" title="Steve Carell"/>
<link href="http://api-public.netflix.com/catalog/people/30014922" rel="http://schemas.netflix.com/catalog/person" title="John Krasinski"/>
<link href="http://api-public.netflix.com/catalog/people/20047634" rel="http://schemas.netflix.com/catalog/person" title="Jenna Fischer"/>
<link href="http://api-public.netflix.com/catalog/people/20028105" rel="http://schemas.netflix.com/catalog/person" title="Rainn Wilson"/>
</cast>
</link>
{
"@context" : "http://schema.org",
"@type" : "Article",
"name" : "Legolas",
"image" : "http://img1.wikia.nocookie.net/__cb20070715152604/lotr/images/d/d7/Tengwar_Legolas.png",
"url" : "http://lotr.wikia.com/wiki/Legolas",
"publisher" : {
"@type" : "Organization",
"name" : "[Wikia]"
}
@drsnyder
drsnyder / varnishlog.txt
Created October 30, 2014 19:19
Request to vignette
2242 ReqStart c 74.120.190.15 59269 857607622
2242 RxRequest c GET
2242 RxURL c /vampirediaries/images/2/27/The-originals-season-2-red-door-photos-5.jpg/revision/latest/zoom-crop/width/240/height/240?cb=2014102201002
3
2242 RxProtocol c HTTP/1.1
2242 RxHeader c Accept: image/webp,*/*;q=0.8
2242 RxHeader c User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.94 Safari/537.36
2242 RxHeader c Referer: http://vampirediaries.wikia.com/wiki/Red_Door
2242 RxHeader c Accept-Language: en-GB,en;q=0.8,en-US;q=0.6,en;q=0.4
2242 RxHeader c Fastly-Client-IP: 103.245.70.78