Bye raw_heartbeat_uploads! (#1098)

* Drop raw_heartbeat_uploads

* oops

* Make it friendly

* finalizad

* goog

* bundlarr

* remove the newlines
This commit is contained in:
Mahad Kalam 2026-03-22 18:16:19 +00:00 committed by GitHub
parent 8681dbd9bc
commit 95580df3ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 30 additions and 45 deletions

View file

@ -82,7 +82,7 @@ GEM
ast (2.4.3)
autotuner (1.1.0)
aws-eventstream (1.4.0)
aws-partitions (1.1227.0)
aws-partitions (1.1229.0)
aws-sdk-core (3.244.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
@ -300,7 +300,7 @@ GEM
activesupport (>= 7.1)
marcel (1.1.0)
matrix (0.4.3)
mcp (0.8.0)
mcp (0.9.0)
json-schema (>= 4.1)
memory_profiler (1.1.0)
mini_magick (5.3.1)
@ -329,21 +329,21 @@ GEM
net-ssh (>= 5.0.0, < 8.0.0)
net-smtp (0.5.1)
net-protocol
net-ssh (7.3.1)
net-ssh (7.3.2)
nio4r (2.7.5)
nokogiri (1.19.1-aarch64-linux-gnu)
nokogiri (1.19.2-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.1-aarch64-linux-musl)
nokogiri (1.19.2-aarch64-linux-musl)
racc (~> 1.4)
nokogiri (1.19.1-arm-linux-gnu)
nokogiri (1.19.2-arm-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.1-arm-linux-musl)
nokogiri (1.19.2-arm-linux-musl)
racc (~> 1.4)
nokogiri (1.19.1-arm64-darwin)
nokogiri (1.19.2-arm64-darwin)
racc (~> 1.4)
nokogiri (1.19.1-x86_64-linux-gnu)
nokogiri (1.19.2-x86_64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.1-x86_64-linux-musl)
nokogiri (1.19.2-x86_64-linux-musl)
racc (~> 1.4)
norairrecord (0.5.1)
faraday (>= 1.0, < 3.0)

View file

@ -3,7 +3,6 @@ class Api::Hackatime::V1::HackatimeController < ApplicationController
skip_before_action :verify_authenticity_token
skip_before_action :enforce_lockout
before_action :check_lockout, only: [ :push_heartbeats ]
before_action :set_raw_heartbeat_upload, only: [ :push_heartbeats ], if: :is_blank?
def push_heartbeats
# Handle both single and bulk heartbeats based on format
@ -175,11 +174,6 @@ class Api::Hackatime::V1::HackatimeController < ApplicationController
private
def is_blank?
body = body_to_json
body.present? && (body.is_a?(Array) ? body.any? : true)
end
def calculate_category_stats(heartbeats, category)
durations = heartbeats.group(category).duration_seconds
@ -216,13 +210,6 @@ class Api::Hackatime::V1::HackatimeController < ApplicationController
end.sort_by { |item| -item[:total_seconds] }
end
def set_raw_heartbeat_upload
@raw_heartbeat_upload = RawHeartbeatUpload.create!(
request_headers: headers_to_json,
request_body: body_to_json
)
end
def headers_to_json
request.headers
.env
@ -288,10 +275,7 @@ class Api::Hackatime::V1::HackatimeController < ApplicationController
machine: request.headers["X-Machine-Name"]
})
new_heartbeat = Heartbeat.find_or_create_by(attrs)
if @raw_heartbeat_upload.present? && new_heartbeat.persisted?
new_heartbeat.raw_heartbeat_upload ||= @raw_heartbeat_upload
new_heartbeat.save! if new_heartbeat.changed?
end
queue_project_mapping(heartbeat[:project])
results << [ new_heartbeat.attributes, 201 ]
rescue => e

View file

@ -86,7 +86,6 @@ class Heartbeat < ApplicationRecord
self.inheritance_column = nil
belongs_to :user
belongs_to :raw_heartbeat_upload, optional: true
validates :time, presence: true

View file

@ -1,6 +0,0 @@
class RawHeartbeatUpload < ApplicationRecord
has_many :heartbeats
validates :request_headers, presence: true
validates :request_body, presence: true
end

View file

@ -0,0 +1,18 @@
class DropRawHeartbeatUploads < ActiveRecord::Migration[8.1]
def up
if foreign_key_exists?(:heartbeats, :raw_heartbeat_uploads)
remove_foreign_key :heartbeats, :raw_heartbeat_uploads
end
if index_exists?(:heartbeats, :raw_heartbeat_upload_id)
remove_index :heartbeats, :raw_heartbeat_upload_id
end
if column_exists?(:heartbeats, :raw_heartbeat_upload_id)
remove_column :heartbeats, :raw_heartbeat_upload_id
end
drop_table :raw_heartbeat_uploads, if_exists: true
end
def down
raise ActiveRecord::IrreversibleMigration
end
end

12
db/schema.rb generated
View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.1].define(version: 2026_03_13_140000) do
ActiveRecord::Schema[8.1].define(version: 2026_03_22_180603) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
enable_extension "pg_stat_statements"
@ -301,7 +301,6 @@ ActiveRecord::Schema[8.1].define(version: 2026_03_13_140000) do
t.string "operating_system"
t.string "project"
t.integer "project_root_count"
t.bigint "raw_heartbeat_upload_id"
t.integer "source_type", null: false
t.float "time", null: false
t.string "type"
@ -315,7 +314,6 @@ ActiveRecord::Schema[8.1].define(version: 2026_03_13_140000) do
t.index ["machine"], name: "index_heartbeats_on_machine"
t.index ["project", "time"], name: "index_heartbeats_on_project_and_time"
t.index ["project"], name: "index_heartbeats_on_project"
t.index ["raw_heartbeat_upload_id"], name: "index_heartbeats_on_raw_heartbeat_upload_id"
t.index ["source_type", "time", "user_id", "project"], name: "index_heartbeats_on_source_type_time_user_project"
t.index ["user_agent"], name: "index_heartbeats_on_user_agent"
t.index ["user_id", "category", "time"], name: "idx_heartbeats_user_category_time", where: "(deleted_at IS NULL)"
@ -488,13 +486,6 @@ ActiveRecord::Schema[8.1].define(version: 2026_03_13_140000) do
t.index ["user_id"], name: "index_project_repo_mappings_on_user_id"
end
create_table "raw_heartbeat_uploads", force: :cascade do |t|
t.datetime "created_at", null: false
t.jsonb "request_body", null: false
t.jsonb "request_headers", null: false
t.datetime "updated_at", null: false
end
create_table "repo_host_events", id: :string, force: :cascade do |t|
t.datetime "created_at", null: false
t.integer "provider", default: 0, null: false
@ -683,7 +674,6 @@ ActiveRecord::Schema[8.1].define(version: 2026_03_13_140000) do
add_foreign_key "goals", "users"
add_foreign_key "heartbeat_import_runs", "users"
add_foreign_key "heartbeat_import_sources", "users"
add_foreign_key "heartbeats", "raw_heartbeat_uploads"
add_foreign_key "heartbeats", "users"
add_foreign_key "leaderboard_entries", "leaderboards"
add_foreign_key "leaderboard_entries", "users"