diff --git a/lambda/web/app/app.rb b/lambda/web/app/app.rb index 743938f..bb9b3ce 100644 --- a/lambda/web/app/app.rb +++ b/lambda/web/app/app.rb @@ -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 diff --git a/lambda/web/app/models/tweet.rb b/lambda/web/app/models/tweet.rb index 115fb5a..c0972eb 100644 --- a/lambda/web/app/models/tweet.rb +++ b/lambda/web/app/models/tweet.rb @@ -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 diff --git a/lambda/web/web.zip b/lambda/web/web.zip new file mode 100644 index 0000000..ea2c548 Binary files /dev/null and b/lambda/web/web.zip differ