Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve livecomments #7

Merged
merged 6 commits into from Nov 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 17 additions & 9 deletions webapp/ruby/app.rb
Expand Up @@ -159,16 +159,25 @@ def batch_fill_livestream_response(tx, livestream_models)
end

def fill_livecomment_response(tx, livecomment_model)
comment_owner_model = tx.xquery('SELECT * FROM users WHERE id = ?', livecomment_model.fetch(:user_id)).first
batch_fill_livecomment_response(tx, [livecomment_model])[0]
end

def batch_fill_livecomment_response(tx, livecomment_models)
head_livecomment = livecomment_models.first
return [] if head_livecomment.nil?

comment_owner_model = tx.xquery('SELECT * FROM users WHERE id = ?', livecomment_models.first.fetch(:user_id)).first
comment_owner = fill_user_response(tx, comment_owner_model)

livestream_model = tx.xquery('SELECT * FROM livestreams WHERE id = ?', livecomment_model.fetch(:livestream_id)).first
livestream_model = tx.xquery('SELECT * FROM livestreams WHERE id = ?', livecomment_models.first.fetch(:livestream_id)).first
livestream = fill_livestream_response(tx, livestream_model)

livecomment_model.slice(:id, :comment, :tip, :created_at).merge(
user: comment_owner,
livestream:,
)
livecomments = livecomment_models.map do |livecomment_model|
livecomment_model.slice(:id, :comment, :tip, :created_at).merge(
user: comment_owner,
livestream:,
)
end
end

def fill_livecomment_report_response(tx, report_model)
Expand Down Expand Up @@ -551,9 +560,8 @@ def batch_fill_user_response(tx, user_models)
query = "#{query} LIMIT #{limit}"
end

tx.xquery(query, livestream_id).map do |livecomment_model|
fill_livecomment_response(tx, livecomment_model)
end
livecomment_models = tx.xquery(query, livestream_id)
batch_fill_livecomment_response(tx, livecomment_models)
end

json(livecomments)
Expand Down