Skip to content

Commit 5df299d

Browse files
committed
Add 'Until' column to contributors index
1 parent bc321ae commit 5df299d

22 files changed

+127
-327
lines changed

app/assets/stylesheets/screen.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ TABLES GENERALS
330330
font-size: 1.1em;
331331
}
332332

333-
#table-wrap table td.contributor-since {
333+
#table-wrap table td.contributor-timestamp {
334334
white-space: nowrap;
335335
text-align: left;
336336
}

app/models/contributor.rb

+19-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def self._all_with_ncommits(joins, where=nil)
3939
order('ncommits DESC, contributors.url_id ASC')
4040
end
4141

42-
def self.set_first_contribution_timestamps(only_new)
43-
scope = only_new ? 'first_contribution_at IS NULL' : '1 = 1'
42+
def self.set_first_contribution_timestamps(only_missing)
43+
scope = only_missing ? 'first_contribution_at IS NULL' : '1 = 1'
4444

4545
connection.execute(<<-SQL)
4646
UPDATE contributors
@@ -56,6 +56,23 @@ def self.set_first_contribution_timestamps(only_new)
5656
SQL
5757
end
5858

59+
def self.set_last_contribution_timestamps(only_missing)
60+
scope = only_missing ? 'last_contribution_at IS NULL' : '1 = 1'
61+
62+
connection.execute(<<-SQL)
63+
UPDATE contributors
64+
SET last_contribution_at = last_contributions.committer_date
65+
FROM (
66+
SELECT contributor_id, MAX(commits.committer_date) AS committer_date
67+
FROM contributions
68+
INNER JOIN commits ON commits.id = commit_id
69+
GROUP BY contributor_id
70+
) AS last_contributions
71+
WHERE id = last_contributions.contributor_id
72+
AND #{scope}
73+
SQL
74+
end
75+
5976
# The contributors table may change if new name equivalences are added and IDs
6077
# in particular are expected to move. So, we just put the parameterized name
6178
# in URLs, which is unique anyway.

app/models/repo.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def sync
8585
if ncommits > 0 || nreleases > 0 || rebuild_all
8686
sync_names
8787
sync_ranks
88-
sync_first_contribution_timestamps
88+
sync_contribution_timestamps
8989
end
9090

9191
RepoUpdate.create!(
@@ -188,8 +188,9 @@ def sync_ranks
188188
end
189189
end
190190

191-
def sync_first_contribution_timestamps
191+
def sync_contribution_timestamps
192192
Contributor.set_first_contribution_timestamps(!rebuild_all)
193+
Contributor.set_last_contribution_timestamps(!rebuild_all)
193194
end
194195

195196
# Determines whether the names mapping has been updated. This is useful because

app/views/contributors/_contributor.html.erb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
<tr class="<%= cycle 'even', 'odd' %>">
1+
<tr id="<%= contributor.name.downcase.tr(' ', '-') %>" class="<%= cycle 'even', 'odd' %>">
22
<td class="contributor-rank">#<%= contributor.rank %></td>
33
<td class="contributor-name"><%= link_to_contributor contributor %></td>
4-
<td class="contributor-since"><%= date contributor.first_contribution_at %></td>
4+
<td class="contributor-timestamp"><%= date contributor.first_contribution_at %></td>
5+
<td class="contributor-timestamp"><%= date contributor.last_contribution_at %></td>
56
<td class="no-commits">
67
<% path = if @time_window
78
contributor_commits_in_time_window_path(contributor, @time_window)

app/views/contributors/index.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<th></th>
1515
<th>Name</th>
1616
<th>Since</th>
17+
<th>Until</th>
1718
<th>Commits</th>
1819
</tr>
1920
<%= render @contributors %>

db/migrate/20150326181907_add_first_contribution_at_to_contributors.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class AddFirstContributionAtToContributors < ActiveRecord::Migration[4.2]
22
def up
33
add_column :contributors, :first_contribution_at, :datetime
4-
Contributor.try(:fill_missing_first_contribution_timestamps)
4+
Contributor.set_first_contribution_timestamps
55
end
66

77
def down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class AddLastContributionAtToContributors < ActiveRecord::Migration[7.1]
2+
def up
3+
add_column :contributors, :last_contribution_at, :datetime
4+
Contributor.set_last_contribution_timestamps
5+
end
6+
7+
def down
8+
remove_column :contributors, :last_contribution_at
9+
end
10+
end

db/schema.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2016_05_12_095609) do
13+
ActiveRecord::Schema[7.1].define(version: 2024_08_24_030051) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

@@ -42,6 +42,7 @@
4242
t.string "url_id", null: false
4343
t.integer "rank"
4444
t.datetime "first_contribution_at", precision: nil
45+
t.datetime "last_contribution_at"
4546
t.index ["name"], name: "index_contributors_on_name", unique: true
4647
t.index ["url_id"], name: "index_contributors_on_url_id", unique: true
4748
end

public/404.html

-67
This file was deleted.

public/406-unsupported-browser.html

-66
This file was deleted.

public/422.html

-67
This file was deleted.

public/500.html

-66
This file was deleted.

public/favicon.ico

Whitespace-only changes.

0 commit comments

Comments
 (0)