Skip to content

Commit

Permalink
Add insider trades pagination and adjust stocks pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Shpigford committed Nov 20, 2024
1 parent e58d8c8 commit 4d40419
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
28 changes: 22 additions & 6 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,23 @@ def sitemap
@sectors = Stock.where(kind: "stock").where.not(mic_code: nil).where.not(sector: nil).distinct.pluck(:sector).compact.sort
@exchange_rate_currencies = Tool::Presenter::ExchangeRateCalculator.new.currency_options

# Paginate stocks
@stocks = Stock.order(name: :asc)
.where.not(mic_code: nil)
.offset((@page - 1) * 20_000)
.limit(20_000)
# Add insider trades pagination
@insider_trades = Stock.where(kind: "stock", country_code: "US")
.where.not(mic_code: nil)
.order(name: :asc)
.offset((@page - 1) * 20_000)
.limit(20_000)

# Adjust stocks pagination to start after insider trades pages
stocks_page = @page - (Stock.where(kind: "stock", country_code: "US").count / 20_000.0).ceil
@stocks = if stocks_page > 0
Stock.order(name: :asc)
.where.not(mic_code: nil)
.offset((stocks_page - 1) * 20_000)
.limit(20_000)
else
Stock.none
end

respond_to do |format|
format.xml
Expand All @@ -66,8 +78,12 @@ def sitemap
#
# @return [XML] Sitemap index file
def sitemap_index
@us_stocks_count = Stock.where(kind: "stock", country_code: "US").where.not(mic_code: nil).count
@total_stocks = Stock.where.not(mic_code: nil).count
@sitemap_count = (@total_stocks / 20_000.0).ceil # Using 20k to leave room for other URLs

@insider_trades_pages = (@us_stocks_count / 20_000.0).ceil
@stocks_pages = ((@total_stocks - @us_stocks_count) / 20_000.0).ceil
@sitemap_count = @insider_trades_pages + @stocks_pages

respond_to do |format|
format.xml
Expand Down
14 changes: 14 additions & 0 deletions app/views/pages/sitemap.xml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@
</url>
<% end %>
<% end %>
<url>
<loc>https://maybe.co/tools/inside-trading-tracker/top-owners</loc>
</url>
<url>
<loc>https://maybe.co/tools/inside-trading-tracker/biggest-trades</loc>
</url>
<url>
<loc>https://maybe.co/tools/inside-trading-tracker/top-officers</loc>
</url>
<% @insider_trades.each do |stock| %>
<url>
<loc>https://maybe.co/tools/inside-trading-tracker/<%= stock.symbol %></loc>
</url>
<% end %>
<% @stocks.each do |stock| %>
<url>
Expand Down

0 comments on commit 4d40419

Please sign in to comment.