Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add orphans option to reprocess command #245

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bitmagnet.io/tutorials/reprocess-reclassify.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ The `reprocess` command will re-queue torrents to allow the latest updates to be
To reprocess all torrents in your index, simply run `bitmagnet reprocess`. If you've indexed a lot of torrents, this will take a while, so there are a few options available to control exactly what gets reprocessed:

- `contentType`: Only reprocess torrents of a certain content type. For example, `bitmagnet reprocess --contentType movie` will only reprocess movies. Multiple content types can be comma separated, and `null` refers to torrents of unknown content type.
- `classifyMode`: This controls how already matched torrents are handled. A torrent is "matched" if it's associated with a specific piece of content from one of the API integrations (currently only TMDB). Making a lot of API calls can take a long time, so if items are already matched you might want to just do the other processing steps without re-matching them. The available modes are:
- `orphans`: Only reprocess torrents that have no content record.
- `classifyMode`: This controls how already matched torrents are handled.
- `default`: Only attempt to match previously unmatched torrents
- `rematch`: Ignore any pre-existing match and always classify from scratch
- `rematch`: Ignore any pre-existing match and always classify from scratch (A torrent is "matched" if it's associated with a specific piece of content from one of the API integrations, currently only TMDB)

\*hints tell the classifier to use the hinted information instead of any classification results, which can save a lot of work for the classifier and help fix errors. Currently, the only way to add hints is by using [the `/import` endpoint](/tutorials/import.html).
15 changes: 15 additions & 0 deletions internal/app/cmd/reprocesscmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func New(p Params) (Result, error) {
strings.Join(model.ContentTypeNames(), "', '") +
"', or 'null' for unknown)",
},
&cli.BoolFlag{
Name: "orphans",
Usage: "reprocess only torrents that have no torrent_contents record",
},
&cli.StringFlag{
Name: "classifyMode",
Value: "default",
Expand Down Expand Up @@ -88,6 +92,17 @@ func New(p Params) (Result, error) {
return tx.Where(gen.Exists(sq))
})
}
if ctx.Bool("orphans") {
scopes = append(scopes, func(tx gen.Dao) gen.Dao {
return tx.Not(
gen.Exists(
d.TorrentContent.Where(
d.TorrentContent.InfoHash.EqCol(d.Torrent.InfoHash),
),
),
)
})
}
batchSize := ctx.Int("batchSize")
torrentCount := int64(0)
if result, err := d.Torrent.WithContext(ctx.Context).Scopes(scopes...).Count(); err != nil {
Expand Down
Loading