Skip to content

Commit

Permalink
Merge pull request #1 from st-tech/bugfix-ranking
Browse files Browse the repository at this point in the history
Bugfix ranking
  • Loading branch information
katsuyan authored Apr 19, 2019
2 parents 5bc2111 + 0f3901e commit ad7250d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
6 changes: 1 addition & 5 deletions lambda/web/app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
require './app/models/tweet.rb'

get '/' do
@tweets = Tweet
.not_deleted
.order_by_score_desc
.limit(5)
.scoped
@tweets = Tweet.ranking
erb :index
end
29 changes: 9 additions & 20 deletions lambda/web/app/models/tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,24 @@ class Tweet
TABLE_NAME = 'Tweets'.freeze

class << self
def ranking
order_by_score_desc
.reject { |t| t.delete_flag }
.take(15)
end

def all
params = {
table_name: TABLE_NAME,
select: 'ALL_ATTRIBUTES',
}

@scoped = db.scan(params)
.map { |attrs| self.new(parse(attrs)) }
self
db.scan(params)
.map { |attrs| self.new(parse(attrs)) }
end

def order_by_score_desc
@scoped = scoped.sort_by { |t| t.score }.reverse!
self
end

def not_deleted
@scoped = scoped.reject { |t| t.delete_flag }
self
end

def limit(limit)
@scoped = scoped.take limit
self
end

def scoped
all unless @scoped
@scoped
all.sort_by { |t| t.score }.reverse!
end

def create_table
Expand Down
Binary file added lambda/web/web.zip
Binary file not shown.

0 comments on commit ad7250d

Please sign in to comment.