Skip to content

Commit 3f9e7b5

Browse files
committed
fix fuck ass timestamping
1 parent d0d8e38 commit 3f9e7b5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

app/controllers/api/admin/v1/admin_controller.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ def check
2525
def user_info
2626
user = find_user_by_id
2727
return unless user
28-
valid = user.heartbeats.where("time BETWEEN ? AND ?", Time.utc(2000, 1, 1).to_i, Time.utc(2100, 1, 1).to_i)
28+
valid = user.heartbeats.where("CASE WHEN time > 1000000000000 THEN time / 1000 ELSE time END BETWEEN ? AND ?", Time.utc(2000, 1, 1).to_i, Time.utc(2100, 1, 1).to_i)
29+
30+
lht = valid.maximum(:time)
31+
if lht && lht > 1000000000000
32+
lht = lht / 1000
33+
end
2934

3035
render json: {
3136
user: {
@@ -43,15 +48,15 @@ def user_info
4348
banned: user.trust_level == "red",
4449
created_at: user.created_at,
4550
updated_at: user.updated_at,
46-
last_heartbeat_at: valid.maximum(:time),
51+
last_heartbeat_at: lht,
4752
email_addresses: user.email_addresses.map(&:email),
4853
api_keys_count: user.api_keys.count,
4954
stats: {
5055
total_heartbeats: valid.count,
5156
total_coding_time: valid.duration_seconds || 0,
5257
languages_used: valid.distinct.pluck(:language).compact.count,
5358
projects_worked_on: valid.distinct.pluck(:project).compact.count,
54-
days_active: valid.distinct.count("DATE(to_timestamp(time))")
59+
days_active: valid.distinct.count("DATE(to_timestamp(CASE WHEN time > 1000000000000 THEN time / 1000 ELSE time END))")
5560
}
5661
}
5762
}

0 commit comments

Comments
 (0)