This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StoryController < ApplicationController | |
#require 'utility' | |
def index | |
@story = Story.get(params[:id]) | |
#@comments = repository(:default).adapter.query('SELECT comments.id, story_id, user_id, parent_id, time, sid, cid, pid, subject, recrate, trollrate, raters, commentip, comment, nickname from comments left join users on comments.user_id = users.id where story_id = ?', @story.id) | |
#@comments = Comment.find_by_sql(['SELECT comments.id, subject, nickname from comments left join users on comments.user_id = users.id where story_id = ?', @story.id]) | |
# experiment... | |
clist = repository(:default).adapter.query('SELECT comments.id, story_id, user_id, parent_id, time, sid, cid, pid, subject, recrate, trollrate, raters, commentip, comment, nickname from comments left join users on comments.user_id = users.id where story_id = ?', @story.id) | |
chash = Hash.new | |
@comments = Array.new | |
# order this shit, and quick | |
clist.each do |c| | |
chash[c.parent_id] = Array.new if chash[c.parent_id].nil? | |
chash[c.parent_id].push(c) | |
end | |
cproc = Proc.new { |s| unless (chash[s].nil?); chash[s].each { |i| @comments.push(i); cproc.call(i.id)} end } | |
#chash.each_key { |k| cproc.call(k) } | |
cproc.call(0) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment