Class: InstantRecord::RecordsController
- Inherits:
-
ActionController::API
- Object
- ActionController::API
- InstantRecord::RecordsController
- Defined in:
- app/controllers/instant_record/records_controller.rb
Overview
Keyset-cursor history pages for windowed models: rows strictly below the (created_at, id) tuple, newest first. Backs InstantRecord.fetch_history; never uses OFFSET, so page cost stays flat at any depth.
Constant Summary collapse
- HARD_LIMIT =
Independent of any model's window size: the ceiling a client can request in one page.
200
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/instant_record/records_controller.rb', line 12 def index model = InstantRecord.synced_model(params[:type]) return head :not_found unless model window = model.instant_record_sync_window return head :unprocessable_entity unless window return head :bad_request if window.partition_by && params[:partition].blank? before_at = parse_time(params[:before_created_at]) return head :bad_request if before_at.nil? || params[:before_id].blank? limit = (params[:limit].presence || window.limit).to_i.clamp(1, HARD_LIMIT) rows = window .keyset_below(at: before_at, id: params[:before_id], partition: params[:partition]) .limit(limit + 1) .to_a render json: { records: rows.first(limit).map { |record| InstantRecord.record_payload(record) }, has_more: rows.size > limit } end |