Skip to content

Commit abdb714

Browse files
authored
Add local_search_enabled flag to classifier (#291)
* Add local_search_enabled flag * Add comment * Update documentation
1 parent b05e5d1 commit abdb714

File tree

7 files changed

+33
-3
lines changed

7 files changed

+33
-3
lines changed

bitmagnet.io/guides/reprocess-reclassify.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The `reprocess` command will re-queue torrents to allow the latest updates to be
2525
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:
2626

2727
- `apisDisabled`: Disable API calls during classification. This makes the classifier run a _lot_ faster, but disables identification with external services such as TMDB (metadata already gathered from external APIs is not lost).
28+
- `localSearchDisabled`: Disable the local search query on the content table for matching torrents to known content. This should be tried before any external API call is attempted, but it's an expensive query and so it's useful to be able to disable it using this flag.
2829
- `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.
2930
- `orphans`: Only reprocess torrents that have no content record.
3031
- `classifyMode`: This controls how already matched torrents are handled.

internal/app/cmd/processcmd/command.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ func New(p Params) (Result, error) {
3939
Value: false,
4040
Usage: "disable API calls for the classifier workflow",
4141
},
42+
&cli.BoolFlag{
43+
Name: "localSearchDisabled",
44+
Value: false,
45+
Usage: "disable local search queries for the classifier workflow",
46+
},
4247
},
4348
Action: func(ctx *cli.Context) error {
4449
pr, err := p.Processor.Get()
@@ -53,6 +58,9 @@ func New(p Params) (Result, error) {
5358
if ctx.Bool("apisDisabled") {
5459
flags["apis_enabled"] = false
5560
}
61+
if ctx.Bool("localSearchDisabled") {
62+
flags["local_search_enabled"] = false
63+
}
5664
var infoHashes []protocol.ID
5765
for _, infoHash := range ctx.StringSlice("infoHash") {
5866
id, err := protocol.ParseID(infoHash)

internal/app/cmd/reprocesscmd/command.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func New(p Params) (Result, error) {
6666
Value: false,
6767
Usage: "disable API calls for the classifier workflow",
6868
},
69+
&cli.BoolFlag{
70+
Name: "localSearchDisabled",
71+
Value: false,
72+
Usage: "disable local search queries for the classifier workflow",
73+
},
6974
},
7075
Action: func(ctx *cli.Context) error {
7176
var classifyMode processor.ClassifyMode
@@ -85,6 +90,9 @@ func New(p Params) (Result, error) {
8590
if ctx.Bool("apisDisabled") {
8691
flags["apis_enabled"] = false
8792
}
93+
if ctx.Bool("localSearchDisabled") {
94+
flags["local_search_enabled"] = false
95+
}
8896
var contentTypes []model.NullContentType
8997
for _, contentType := range ctx.StringSlice("contentType") {
9098
if contentType == "null" {

internal/classifier/classifier.core.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ workflows:
8989
condition: "!result.hasAttachedContent && result.hasBaseTitle"
9090
if_action:
9191
find_match:
92-
- attach_local_content_by_search
92+
- if_else:
93+
condition: "flags.local_search_enabled"
94+
if_action: attach_local_content_by_search
95+
else_action: unmatched
9396
- if_else:
9497
condition: "flags.apis_enabled && flags.tmdb_enabled"
9598
if_action: attach_tmdb_content_by_search
@@ -226,11 +229,13 @@ keywords:
226229
- yvm
227230
- (#|10|11|12|13|14|15|16|17) ?y ?o
228231
flag_definitions:
232+
local_search_enabled: bool
229233
apis_enabled: bool
230234
tmdb_enabled: bool
231235
delete_content_types: content_type_list
232236
delete_xxx: bool
233237
flags:
238+
local_search_enabled: true
234239
apis_enabled: true
235240
tmdb_enabled: true
236241
delete_content_types: []

internal/processor/batch/queue/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func New(p Params) Result {
7272
priority := 10
7373
// prioritise jobs where API calls are disabled as they will run faster:
7474
if msg.ApisDisabled() {
75-
priority = 5
75+
priority = 4
7676
}
7777
maxInfoHash := msg.InfoHashGreaterThan
7878
chunkSize := uint(0)

internal/processor/hook_0_9_0/hook.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ func execHook(d *dao.Query) error {
6262
job, jobErr := batch.NewQueueJob(batch.MessageParams{
6363
UpdatedBefore: time.Now(),
6464
ClassifierFlags: classifier.Flags{
65-
"apis_enabled": false,
65+
"apis_enabled": false,
66+
"local_search_enabled": false,
6667
},
6768
ChunkSize: 10_000,
6869
BatchSize: 100,

internal/processor/queue/handler.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ func New(p Params) Result {
3434
if err := json.Unmarshal([]byte(job.Payload), msg); err != nil {
3535
return err
3636
}
37+
// The following is somewhat of a hack to alter the `local_search_enabled` flag for jobs queued by the upgrade hook between 0.9.0 and 0.9.3.
38+
// It should be removed at a later date.
39+
if job.Priority == 5 && msg.ClassifierFlags != nil {
40+
if _, ok := msg.ClassifierFlags["local_search_enabled"]; !ok {
41+
msg.ClassifierFlags["local_search_enabled"] = false
42+
}
43+
}
3744
return pr.Process(ctx, *msg)
3845
}, handler.JobTimeout(time.Second*60*10), handler.Concurrency(int(p.Config.Concurrency))), nil
3946
}),

0 commit comments

Comments
 (0)