From 81673dcde8684739648654f7cb8216c41a2621c8 Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Wed, 24 Apr 2013 12:46:43 +1000
Subject: [PATCH] slug memoization in the table

---
 app/models/topic.rb | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/app/models/topic.rb b/app/models/topic.rb
index 2bfd0c9beb0..02f936faf9c 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -598,7 +598,24 @@ class Topic < ActiveRecord::Base
   end
 
   def slug
-    Slug.for(title).presence || "topic"
+    unless slug = read_attribute(:slug)
+      return '' unless title.present?
+      slug = Slug.for(title).presence || "topic"
+      if new_record?
+        write_attribute(:slug, slug)
+      else
+        update_column(:slug, slug)
+      end
+    end
+
+    slug
+  end
+
+  def title=(t)
+    slug = ""
+    slug = (Slug.for(t).presence || "topic") if t.present?
+    write_attribute(:slug, slug)
+    write_attribute(:title,t)
   end
 
   def last_post_url