Skip to content

Commit c126e55

Browse files
committed
Use previous org repo stats for star repair
1 parent 872fbb3 commit c126e55

7 files changed

Lines changed: 19 additions & 19 deletions

File tree

docs/crawl-jobs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Monthly ranking resume behavior:
157157
- `--use-stars-diff` uses previous stored repository star observations instead
158158
of fetching monthly star history again from the source API.
159159
- `--refresh-organization-stars` repairs organization repository monthly star
160-
deltas from the previous stored repository star observations and recomputes
160+
deltas from the previous stored monthly repository stats and recomputes
161161
organization star totals from those repository rows.
162162

163163
Package ranking resume behavior:

lib/polish_open_source_rank/contexts/ranking/application/monthly_source_metric_backfill.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ def refresh_organization_repository_stars_for_source(period, source)
146146
work = BACKFILL_WORK.fetch(:organization_repository_stars)
147147
return if completed_subject_ids(period, source, work).include?(source.platform)
148148

149-
log(source, 'refreshing organization repository stars from stored observations')
149+
log(source, 'refreshing organization repository stars from previous monthly stats')
150150
record_work_event(
151151
period,
152152
work.merge(platform: source.platform, subject_id: source.platform, subject_label: source.platform)
153153
) do
154-
store.refresh_organization_repository_star_deltas_from_observations(
154+
store.refresh_organization_repository_star_deltas_from_previous_stats(
155155
period,
156156
platform: source.platform
157157
)

lib/polish_open_source_rank/contexts/ranking/infrastructure/sqlite/monthly_snapshot_store.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def organization_stats_for_period(period, platform:)
116116
snapshot_repository.organization_stats_for_period(period, platform)
117117
end
118118

119-
def refresh_organization_repository_star_deltas_from_observations(period, platform:)
120-
snapshot_repository.refresh_organization_repository_star_deltas_from_observations(
119+
def refresh_organization_repository_star_deltas_from_previous_stats(period, platform:)
120+
snapshot_repository.refresh_organization_repository_star_deltas_from_previous_stats(
121121
period,
122122
platform: platform
123123
)

lib/polish_open_source_rank/contexts/ranking/infrastructure/sqlite/sqlite_snapshot_repository.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ class SQLiteSnapshotRepository
1111
SET monthly_stars_delta = COALESCE((
1212
SELECT MAX(
1313
organization_repository_monthly_stats.stargazers_count -
14-
previous_observations.stargazers_count,
14+
previous_stats.stargazers_count,
1515
0
1616
)
17-
FROM organization_repository_star_observations previous_observations
18-
WHERE previous_observations.period_start = ?
19-
AND previous_observations.platform = organization_repository_monthly_stats.platform
20-
AND previous_observations.repository_github_id =
17+
FROM organization_repository_monthly_stats previous_stats
18+
WHERE previous_stats.period_start = ?
19+
AND previous_stats.platform = organization_repository_monthly_stats.platform
20+
AND previous_stats.repository_github_id =
2121
organization_repository_monthly_stats.repository_github_id
2222
), 0),
2323
updated_at = ?
@@ -177,7 +177,7 @@ def organization_stats_for_period(period, platform)
177177
SQL
178178
end
179179

180-
def refresh_organization_repository_star_deltas_from_observations(period, platform:)
180+
def refresh_organization_repository_star_deltas_from_previous_stats(period, platform:)
181181
database.execute(
182182
REFRESH_ORGANIZATION_REPOSITORY_STAR_DELTAS_SQL,
183183
[previous_period_start(period), timestamp, period.start_date.to_s, platform]

spec/polish_open_source_rank/contexts/ranking/application/monthly_source_metric_backfill_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
)
152152
end
153153

154-
it 'refreshes organization repository stars from stored observations' do
154+
it 'refreshes organization repository stars from previous monthly stats' do
155155
source = instance_double(GitHubSource, platform: 'github', supports_organizations?: true)
156156
allow(work_events).to receive(:successful_subject_ids).with(
157157
{
@@ -162,13 +162,13 @@
162162
platform: 'github'
163163
}
164164
).and_return(Set.new)
165-
allow(store).to receive(:refresh_organization_repository_star_deltas_from_observations)
165+
allow(store).to receive(:refresh_organization_repository_star_deltas_from_previous_stats)
166166
allow(store).to receive(:refresh_organization_repository_metrics)
167167

168168
described_class.new(store: store, sources: [source], logger: logger, work_events: work_events)
169169
.call(period, refresh_organization_stars: true)
170170

171-
expect(store).to have_received(:refresh_organization_repository_star_deltas_from_observations)
171+
expect(store).to have_received(:refresh_organization_repository_star_deltas_from_previous_stats)
172172
.with(period, platform: 'github')
173173
expect(store).to have_received(:refresh_organization_repository_metrics).with(period, platform: 'github')
174174
end
@@ -184,13 +184,13 @@
184184
platform: 'github'
185185
}
186186
).and_return(Set['github'])
187-
allow(store).to receive(:refresh_organization_repository_star_deltas_from_observations)
187+
allow(store).to receive(:refresh_organization_repository_star_deltas_from_previous_stats)
188188
allow(store).to receive(:refresh_organization_repository_metrics)
189189

190190
described_class.new(store: store, sources: [source], logger: logger, work_events: work_events)
191191
.call(period, refresh_organization_stars: true)
192192

193-
expect(store).not_to have_received(:refresh_organization_repository_star_deltas_from_observations)
193+
expect(store).not_to have_received(:refresh_organization_repository_star_deltas_from_previous_stats)
194194
expect(store).not_to have_received(:refresh_organization_repository_metrics)
195195
end
196196

spec/polish_open_source_rank/contexts/ranking/infrastructure/sqlite/monthly_snapshot_store_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def exercise_monthly_snapshot_store_contract
6262
allow(snapshot_repository).to receive(:record_organization_snapshot).with(organization_snapshot)
6363
allow(snapshot_repository).to receive(:record_organization_repository_snapshot)
6464
.with(organization_repository_snapshot)
65-
allow(snapshot_repository).to receive(:refresh_organization_repository_star_deltas_from_observations)
65+
allow(snapshot_repository).to receive(:refresh_organization_repository_star_deltas_from_previous_stats)
6666
.with(period, platform: 'gitlab')
6767
allow(snapshot_repository).to receive(:refresh_organization_repository_metrics)
6868
.with(period, platform: 'gitlab')
@@ -100,7 +100,7 @@ def exercise_monthly_snapshot_store_contract
100100
snapshot_store.record_repository_snapshot(repository_snapshot)
101101
snapshot_store.record_organization_snapshot(organization_snapshot)
102102
snapshot_store.record_organization_repository_snapshot(organization_repository_snapshot)
103-
snapshot_store.refresh_organization_repository_star_deltas_from_observations(period, platform: 'gitlab')
103+
snapshot_store.refresh_organization_repository_star_deltas_from_previous_stats(period, platform: 'gitlab')
104104
snapshot_store.refresh_organization_repository_metrics(period, platform: 'gitlab')
105105
snapshot_store.prune_rankings(period)
106106
end

spec/polish_open_source_rank/contexts/ranking/infrastructure/sqlite/sqlite_snapshot_repository_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
repository.record_organization_repository_snapshot(
127127
organization_repository_snapshot(source_id: 201, name: 'docs', stars: 10, delta: 0)
128128
)
129-
repository.refresh_organization_repository_star_deltas_from_observations(period, platform: 'github')
129+
repository.refresh_organization_repository_star_deltas_from_previous_stats(period, platform: 'github')
130130
repository.refresh_organization_repository_metrics(period, platform: 'github')
131131

132132
expect(row('organization_monthly_stats')).to include(

0 commit comments

Comments
 (0)