From 3de3b55d3c71726e087d7fb245c8b07403fede9d Mon Sep 17 00:00:00 2001 From: FireMaskterK <20838718+FireMasterK@users.noreply.github.com> Date: Tue, 9 Nov 2021 08:03:21 +0000 Subject: [PATCH] Revert "Fix LBRY timeouts." This reverts commit a7b02e9566e72f6ea67169fc618e9dbf0483e002. --- .../me/kavin/piped/utils/ResponseHelper.java | 54 +++++++++---------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/src/main/java/me/kavin/piped/utils/ResponseHelper.java b/src/main/java/me/kavin/piped/utils/ResponseHelper.java index 793b942..b5d75da 100644 --- a/src/main/java/me/kavin/piped/utils/ResponseHelper.java +++ b/src/main/java/me/kavin/piped/utils/ResponseHelper.java @@ -116,7 +116,7 @@ public class ResponseHelper { ExceptionUtils.rethrow(e); } return null; - }, Multithreading.getCachedExecutor()); + }); CompletableFuture futureLbryId = CompletableFuture.supplyAsync(() -> { try { @@ -125,20 +125,16 @@ public class ResponseHelper { ExceptionHandler.handle(e); } return null; - }, Multithreading.getCachedExecutor()); + }); CompletableFuture futureLBRY = CompletableFuture.supplyAsync(() -> { try { - String lbryId = null; - - lbryId = futureLbryId.completeOnTimeout(null, 2, TimeUnit.SECONDS).get(); - - return getLBRYStreamURL(lbryId); + return getLBRYStreamURL(futureLbryId); } catch (Exception e) { ExceptionHandler.handle(e); } return null; - }, Multithreading.getCachedExecutor()); + }); final List subtitles = new ObjectArrayList<>(); final List chapters = new ObjectArrayList<>(); @@ -161,7 +157,7 @@ public class ResponseHelper { String lbryURL = null; try { - lbryURL = futureLBRY.completeOnTimeout(null, 3, TimeUnit.SECONDS).get(); + lbryURL = futureLBRY.get(3, TimeUnit.SECONDS); } catch (Exception e) { // ignored } @@ -853,32 +849,23 @@ public class ResponseHelper { if (user != null) { Multithreading.runAsync(() -> { - try { - s.getTransaction().begin(); - if (override) - s.createNativeQuery("delete from users_subscribed where subscriber = :id") - .setParameter("id", user.getId()).executeUpdate(); - + if (override) + user.setSubscribed(Arrays.asList(channelIds)); + else for (String channelId : channelIds) - if (override || !user.getSubscribed().contains(channelId)) - s.createNativeQuery("insert into users_subscribed (subscriber, channel) values (?,?)") - .setParameter(1, user.getId()).setParameter(2, channelId).executeUpdate(); + if (!user.getSubscribed().contains(channelId)) + user.getSubscribed().add(channelId); - if (channelIds.length > 0) { - s.getTransaction().commit(); - } - - s.close(); - } catch (Exception e) { - e.printStackTrace(); + if (channelIds.length > 0) { + s.update(user); + s.beginTransaction().commit(); } + + s.close(); }); for (String channelId : channelIds) { - if (channelId.length() > 0) - break; - Multithreading.runAsyncLimited(() -> { try { @@ -983,10 +970,17 @@ public class ResponseHelper { .getJSONObject("data").getJSONObject("videos").optString(videoId); } - private static final String getLBRYStreamURL(String lbryId) + private static final String getLBRYStreamURL(CompletableFuture futureLbryId) throws IOException, InterruptedException, ExecutionException { - if (lbryId != null && !lbryId.isEmpty()) + String lbryId = ""; + try { + lbryId = futureLbryId.get(2, TimeUnit.SECONDS); + } catch (Exception e) { + // ignored + } + + if (!lbryId.isEmpty()) return new JSONObject( Constants.h2client.send( HttpRequest.newBuilder(URI.create("https://api.lbry.tv/api/v1/proxy?m=get"))