Skip to content

Commit ccbefc1

Browse files
authored
Fix slow migration of published_at field (#240)
1 parent c16f761 commit ccbefc1

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

internal/dhtcrawler/persist.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ func (c *crawler) runPersistSources(ctx context.Context) {
218218
DoUpdates: clause.AssignmentColumns([]string{
219219
string(c.dao.TorrentsTorrentSource.Seeders.ColumnName()),
220220
string(c.dao.TorrentsTorrentSource.Leechers.ColumnName()),
221+
// sets to null, fixes torrents indexed before 0.8.0 with published_at 0001-01-01 00:00:00+00:
222+
string(c.dao.TorrentsTorrentSource.PublishedAt.ColumnName()),
221223
string(c.dao.TorrentsTorrentSource.UpdatedAt.ColumnName()),
222224
}),
223225
},

internal/model/torrents.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ func (t Torrent) Leechers() NullUint {
5454
return leechers
5555
}
5656

57+
var cutoff = time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)
58+
5759
func (t Torrent) PublishedAt() time.Time {
5860
publishedAt := t.CreatedAt
5961
for _, source := range t.Sources {
6062
dt := source.CreatedAt
61-
if source.PublishedAt.Valid {
63+
if source.PublishedAt.Valid && source.PublishedAt.Time.After(cutoff) {
6264
dt = source.PublishedAt.Time
6365
}
6466
if dt.Before(publishedAt) {

migrations/00017_ordering_fields.sql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
-- Fix an egregious error that has been there from day 1:
55
update torrents_torrent_sources set seeders = leechers, leechers = seeders where source = 'dht';
66

7-
-- Fix dates that were not set to null:
8-
update torrents_torrent_sources set published_at = null where published_at = '0001-01-01 00:00:00+00';
9-
107
-- Drop some fairly useless columns that take up a lot of space:
118
alter table torrents_torrent_sources drop column bfsd;
129
alter table torrents_torrent_sources drop column bfpe;

0 commit comments

Comments
 (0)