Skip to content

Commit 01463de

Browse files
committed
Switch up events a bit, make webhooks more efficient
1 parent ebca4fd commit 01463de

14 files changed

Lines changed: 354 additions & 72 deletions

File tree

API/src/main/java/me/egg82/fetcharr/api/event/update/APISearchEvent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.util.Objects;
1010

11+
@Deprecated(since = "2.1.0")
1112
public class APISearchEvent extends AbstractCancellableUpdaterEvent {
1213
private IntList ids;
1314

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package me.egg82.fetcharr.api.event.update.lidarr;
2+
3+
import me.egg82.arr.lidarr.v1.schema.ArtistResource;
4+
import me.egg82.fetcharr.api.FetcharrAPI;
5+
import me.egg82.fetcharr.api.event.update.AbstractCancellableUpdaterEvent;
6+
import me.egg82.fetcharr.api.model.update.Updater;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.Objects;
12+
13+
/**
14+
* Fired before submitting a list of {@link ArtistResource}s to the *arr app for searching
15+
*/
16+
public class LidarrSearchEvent extends AbstractCancellableUpdaterEvent {
17+
private List<ArtistResource> resources;
18+
19+
public LidarrSearchEvent(@NotNull List<@NotNull ArtistResource> resources, @NotNull Updater updater, @NotNull FetcharrAPI api) {
20+
super(updater, api);
21+
22+
this.resources = new ArrayList<>(resources);
23+
}
24+
25+
public @NotNull List<@NotNull ArtistResource> resources() {
26+
return resources;
27+
}
28+
29+
public void resources(@NotNull List<@NotNull ArtistResource> resources) {
30+
this.resources = resources;
31+
}
32+
33+
@Override
34+
public boolean equals(Object o) {
35+
if (!(o instanceof LidarrSearchEvent that)) return false;
36+
if (!super.equals(o)) return false;
37+
return Objects.equals(resources, that.resources);
38+
}
39+
40+
@Override
41+
public int hashCode() {
42+
return Objects.hash(super.hashCode(), resources);
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return "LidarrSearchEvent{" +
48+
"resources=" + resources +
49+
", updater=" + updater +
50+
", api=" + api +
51+
'}';
52+
}
53+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package me.egg82.fetcharr.api.event.update.radarr;
2+
3+
import me.egg82.arr.radarr.v3.schema.MovieResource;
4+
import me.egg82.fetcharr.api.FetcharrAPI;
5+
import me.egg82.fetcharr.api.event.update.AbstractCancellableUpdaterEvent;
6+
import me.egg82.fetcharr.api.model.update.Updater;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.Objects;
12+
13+
/**
14+
* Fired before submitting a list of {@link MovieResource}s to the *arr app for searching
15+
*/
16+
public class RadarrSearchEvent extends AbstractCancellableUpdaterEvent {
17+
private List<MovieResource> resources;
18+
19+
public RadarrSearchEvent(@NotNull List<@NotNull MovieResource> resources, @NotNull Updater updater, @NotNull FetcharrAPI api) {
20+
super(updater, api);
21+
22+
this.resources = new ArrayList<>(resources);
23+
}
24+
25+
public @NotNull List<@NotNull MovieResource> resources() {
26+
return resources;
27+
}
28+
29+
public void resources(@NotNull List<@NotNull MovieResource> resources) {
30+
this.resources = resources;
31+
}
32+
33+
@Override
34+
public boolean equals(Object o) {
35+
if (!(o instanceof RadarrSearchEvent that)) return false;
36+
if (!super.equals(o)) return false;
37+
return Objects.equals(resources, that.resources);
38+
}
39+
40+
@Override
41+
public int hashCode() {
42+
return Objects.hash(super.hashCode(), resources);
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return "RadarrSearchEvent{" +
48+
"resources=" + resources +
49+
", updater=" + updater +
50+
", api=" + api +
51+
'}';
52+
}
53+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package me.egg82.fetcharr.api.event.update.sonarr;
2+
3+
import me.egg82.arr.sonarr.v3.schema.SeriesResource;
4+
import me.egg82.fetcharr.api.FetcharrAPI;
5+
import me.egg82.fetcharr.api.event.update.AbstractCancellableUpdaterEvent;
6+
import me.egg82.fetcharr.api.model.update.Updater;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.Objects;
12+
13+
/**
14+
* Fired before submitting a list of {@link SeriesResource}s to the *arr app for searching
15+
*/
16+
public class SonarrSearchEvent extends AbstractCancellableUpdaterEvent {
17+
private List<SeriesResource> resources;
18+
19+
public SonarrSearchEvent(@NotNull List<@NotNull SeriesResource> resources, @NotNull Updater updater, @NotNull FetcharrAPI api) {
20+
super(updater, api);
21+
22+
this.resources = new ArrayList<>(resources);
23+
}
24+
25+
public @NotNull List<@NotNull SeriesResource> resources() {
26+
return resources;
27+
}
28+
29+
public void resources(@NotNull List<@NotNull SeriesResource> resources) {
30+
this.resources = resources;
31+
}
32+
33+
@Override
34+
public boolean equals(Object o) {
35+
if (!(o instanceof SonarrSearchEvent that)) return false;
36+
if (!super.equals(o)) return false;
37+
return Objects.equals(resources, that.resources);
38+
}
39+
40+
@Override
41+
public int hashCode() {
42+
return Objects.hash(super.hashCode(), resources);
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return "SonarrSearchEvent{" +
48+
"resources=" + resources +
49+
", updater=" + updater +
50+
", api=" + api +
51+
'}';
52+
}
53+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package me.egg82.fetcharr.api.event.update.whisparr;
2+
3+
import me.egg82.arr.whisparr.v3.schema.MovieResource;
4+
import me.egg82.fetcharr.api.FetcharrAPI;
5+
import me.egg82.fetcharr.api.event.update.AbstractCancellableUpdaterEvent;
6+
import me.egg82.fetcharr.api.model.update.Updater;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.Objects;
12+
13+
/**
14+
* Fired before submitting a list of {@link MovieResource}s to the *arr app for searching
15+
*/
16+
public class WhisparrSearchEvent extends AbstractCancellableUpdaterEvent {
17+
private List<MovieResource> resources;
18+
19+
public WhisparrSearchEvent(@NotNull List<@NotNull MovieResource> resources, @NotNull Updater updater, @NotNull FetcharrAPI api) {
20+
super(updater, api);
21+
22+
this.resources = new ArrayList<>(resources);
23+
}
24+
25+
public @NotNull List<@NotNull MovieResource> resources() {
26+
return resources;
27+
}
28+
29+
public void resources(@NotNull List<@NotNull MovieResource> resources) {
30+
this.resources = resources;
31+
}
32+
33+
@Override
34+
public boolean equals(Object o) {
35+
if (!(o instanceof WhisparrSearchEvent that)) return false;
36+
if (!super.equals(o)) return false;
37+
return Objects.equals(resources, that.resources);
38+
}
39+
40+
@Override
41+
public int hashCode() {
42+
return Objects.hash(super.hashCode(), resources);
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return "WhisparrSearchEvent{" +
48+
"resources=" + resources +
49+
", updater=" + updater +
50+
", api=" + api +
51+
'}';
52+
}
53+
}

App/src/main/java/me/egg82/fetcharr/api/model/update/lidarr/LidarrUpdater.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import me.egg82.arr.lidarr.v1.schema.TrackFileResource;
1414
import me.egg82.arr.lidarr.v1.schema.TrackResource;
1515
import me.egg82.fetcharr.api.FetcharrAPI;
16-
import me.egg82.fetcharr.api.event.update.APISearchEvent;
1716
import me.egg82.fetcharr.api.event.update.SelectionCancellationReason;
1817
import me.egg82.fetcharr.api.event.update.lidarr.*;
1918
import me.egg82.fetcharr.api.model.update.AbstractUpdater;
@@ -72,9 +71,9 @@ protected boolean doWork() {
7271

7372
boolean dryRun = api.updateManager().dryRun();
7473

75-
IntList ids = new IntArrayList();
74+
List<ArtistResource> resources = new ArrayList<>();
7675
int attempts = 100;
77-
while (attempts > 0 && ids.size() < searchAmount) {
76+
while (attempts > 0 && resources.size() < searchAmount) {
7877
attempts--;
7978

8079
WeightedArtist a = random.selectOne();
@@ -183,16 +182,20 @@ protected boolean doWork() {
183182
} else {
184183
logger.info("Updating artist {} (\"{}\")", a.artist().id(), a.artist().artistName());
185184
}
186-
ids.add(a.artist().id());
185+
resources.add(a.artist());
187186
arrApi.invalidate(Artist.class, a.artist().id()); // Force refresh on next
188187
arrApi.invalidate(Track.class, Map.of("artistId", a.artist().id())); // Force refresh on next
189188
}
190189

191-
if (!dryRun && !ids.isEmpty()) {
192-
APISearchEvent searchEvent = new APISearchEvent(ids, this, api);
190+
if (!dryRun && !resources.isEmpty()) {
191+
LidarrSearchEvent searchEvent = new LidarrSearchEvent(resources, this, api);
193192
api.bus().post(searchEvent);
194193
if (!searchEvent.cancelled()) {
195-
arrApi.search(searchEvent.ids());
194+
IntList ids = new IntArrayList();
195+
for (ArtistResource r : searchEvent.resources()) {
196+
ids.add(r.id());
197+
}
198+
arrApi.search(ids);
196199
} else {
197200
logger.info("{} cancelled - not performing search for {}_{}", searchEvent.getClass().getSimpleName(), config.type().name(), config.id());
198201
}

App/src/main/java/me/egg82/fetcharr/api/model/update/radarr/RadarrUpdater.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import me.egg82.arr.radarr.v3.schema.MovieResource;
1111
import me.egg82.arr.radarr.v3.schema.TagResource;
1212
import me.egg82.fetcharr.api.FetcharrAPI;
13-
import me.egg82.fetcharr.api.event.update.APISearchEvent;
1413
import me.egg82.fetcharr.api.event.update.SelectionCancellationReason;
1514
import me.egg82.fetcharr.api.event.update.radarr.*;
1615
import me.egg82.fetcharr.api.model.update.AbstractUpdater;
@@ -61,9 +60,9 @@ protected boolean doWork() {
6160

6261
boolean dryRun = api.updateManager().dryRun();
6362

64-
IntList ids = new IntArrayList();
63+
List<MovieResource> resources = new ArrayList<>();
6564
int attempts = 100;
66-
while (attempts > 0 && ids.size() < searchAmount) {
65+
while (attempts > 0 && resources.size() < searchAmount) {
6766
attempts--;
6867

6968
WeightedMovie m = random.selectOne();
@@ -138,15 +137,19 @@ protected boolean doWork() {
138137
} else {
139138
logger.info("Updating movie {} (\"{}\")", m.resource().id(), m.resource().title());
140139
}
141-
ids.add(m.resource().id());
140+
resources.add(m.resource());
142141
arrApi.invalidate(Movie.class, m.resource().id()); // Force refresh on next
143142
}
144143

145-
if (!dryRun && !ids.isEmpty()) {
146-
APISearchEvent searchEvent = new APISearchEvent(ids, this, api);
144+
if (!dryRun && !resources.isEmpty()) {
145+
RadarrSearchEvent searchEvent = new RadarrSearchEvent(resources, this, api);
147146
api.bus().post(searchEvent);
148147
if (!searchEvent.cancelled()) {
149-
arrApi.search(searchEvent.ids());
148+
IntList ids = new IntArrayList();
149+
for (MovieResource r : searchEvent.resources()) {
150+
ids.add(r.id());
151+
}
152+
arrApi.search(ids);
150153
} else {
151154
logger.info("{} cancelled - not performing search for {}_{}", searchEvent.getClass().getSimpleName(), config.type().name(), config.id());
152155
}

App/src/main/java/me/egg82/fetcharr/api/model/update/sonarr/SonarrUpdater.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ protected boolean doWork() {
7171

7272
boolean dryRun = api.updateManager().dryRun();
7373

74-
IntList ids = new IntArrayList();
74+
List<SeriesResource> resources = new ArrayList<>();
7575
int attempts = 100;
76-
while (attempts > 0 && ids.size() < searchAmount) {
76+
while (attempts > 0 && resources.size() < searchAmount) {
7777
attempts--;
7878

7979
WeightedSeries s = random.selectOne();
@@ -166,16 +166,20 @@ protected boolean doWork() {
166166
} else {
167167
logger.info("Updating series {} (\"{}\")", s.series().id(), s.series().title());
168168
}
169-
ids.add(s.series().id());
169+
resources.add(s.series());
170170
arrApi.invalidate(Series.class, s.series().id()); // Force refresh on next
171171
arrApi.invalidate(Episode.class, Map.of("seriesId", s.series().id())); // Force refresh on next
172172
}
173173

174-
if (!dryRun && !ids.isEmpty()) {
175-
APISearchEvent searchEvent = new APISearchEvent(ids, this, api);
174+
if (!dryRun && !resources.isEmpty()) {
175+
SonarrSearchEvent searchEvent = new SonarrSearchEvent(resources, this, api);
176176
api.bus().post(searchEvent);
177177
if (!searchEvent.cancelled()) {
178-
arrApi.search(searchEvent.ids());
178+
IntList ids = new IntArrayList();
179+
for (SeriesResource r : searchEvent.resources()) {
180+
ids.add(r.id());
181+
}
182+
arrApi.search(ids);
179183
} else {
180184
logger.info("{} cancelled - not performing search for {}_{}", searchEvent.getClass().getSimpleName(), config.type().name(), config.id());
181185
}

App/src/main/java/me/egg82/fetcharr/api/model/update/whisparr/WhisparrUpdater.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@
1010
import me.egg82.arr.whisparr.v3.schema.MovieResource;
1111
import me.egg82.arr.whisparr.v3.schema.TagResource;
1212
import me.egg82.fetcharr.api.FetcharrAPI;
13-
import me.egg82.fetcharr.api.event.update.APISearchEvent;
1413
import me.egg82.fetcharr.api.event.update.SelectionCancellationReason;
15-
import me.egg82.fetcharr.api.event.update.whisparr.WhisparrFetchMovieEvent;
16-
import me.egg82.fetcharr.api.event.update.whisparr.WhisparrSelectMovieEvent;
17-
import me.egg82.fetcharr.api.event.update.whisparr.WhisparrSkipMovieSelectionEvent;
18-
import me.egg82.fetcharr.api.event.update.whisparr.WhisparrUpdateMovieEvent;
14+
import me.egg82.fetcharr.api.event.update.whisparr.*;
1915
import me.egg82.fetcharr.api.model.update.AbstractUpdater;
2016
import me.egg82.fetcharr.api.model.update.UpdaterConfigImpl;
2117
import me.egg82.fetcharr.util.WeightedRandom;
@@ -64,9 +60,9 @@ protected boolean doWork() {
6460

6561
boolean dryRun = api.updateManager().dryRun();
6662

67-
IntList ids = new IntArrayList();
63+
List<MovieResource> resources = new ArrayList<>();
6864
int attempts = 100;
69-
while (attempts > 0 && ids.size() < searchAmount) {
65+
while (attempts > 0 && resources.size() < searchAmount) {
7066
attempts--;
7167

7268
WeightedMovie m = random.selectOne();
@@ -141,15 +137,19 @@ protected boolean doWork() {
141137
} else {
142138
logger.info("Updating scene/movie {} (\"{}\")", m.resource().id(), m.resource().title());
143139
}
144-
ids.add(m.resource().id());
140+
resources.add(m.resource());
145141
arrApi.invalidate(Movie.class, m.resource().id()); // Force refresh on next
146142
}
147143

148-
if (!dryRun && !ids.isEmpty()) {
149-
APISearchEvent searchEvent = new APISearchEvent(ids, this, api);
144+
if (!dryRun && !resources.isEmpty()) {
145+
WhisparrSearchEvent searchEvent = new WhisparrSearchEvent(resources, this, api);
150146
api.bus().post(searchEvent);
151147
if (!searchEvent.cancelled()) {
152-
arrApi.search(searchEvent.ids());
148+
IntList ids = new IntArrayList();
149+
for (MovieResource r : searchEvent.resources()) {
150+
ids.add(r.id());
151+
}
152+
arrApi.search(ids);
153153
} else {
154154
logger.info("{} cancelled - not performing search for {}_{}", searchEvent.getClass().getSimpleName(), config.type().name(), config.id());
155155
}

0 commit comments

Comments
 (0)