Skip to content

Latest endpoint for the Activity API not returning all of the latest new gems #5741

Open
@activefx

Description

@activefx

Steps to Reproduce

An API call to Gems.latest

Expected Behavior

Gems.latest is supposed to return the 50 gems most recently added to RubyGems.org for the first time.

Current Behavior

Gems.latest does not appear to return the gems most recently added if a new gem publishes multiple new versions in rapid succession (I believe there may also be other edge cases, such as placeholder gems and beta versions). For example, https://rubygems.org/gems/llama_bot_rails was first published on June 15th, 2025. A call to Gems.latest at this moment returns gems created all the way back to June 11th, 2025, but does not include the llama_bot_rails gem.

Possible Solution

One possible solution would be to use a subquery to find the the first version created before the current version of a Rubygem:

  def self.new_pushed_versions(limit = 5)
    subquery = <<~SQL.squish
      versions.rubygem_id IN (
        SELECT v1.rubygem_id
        FROM versions v1
        WHERE NOT EXISTS (
          SELECT 1
          FROM versions v2
          WHERE v2.rubygem_id = v1.rubygem_id
          AND v2.created_at < v1.created_at
        )
        ORDER BY v1.created_at DESC
        LIMIT :limit
      )
    SQL

    where(subquery, limit: limit)
      .where(latest: true)
      .by_created_at
  end

However, in local testing, this seems slow. Couldn't this method just return Rubygem.order(created_at: :desc).limit(50) instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions