Don't query full video anywhere.

This commit is contained in:
Kavin 2022-11-17 16:24:39 +00:00
parent c2248a1bdc
commit a15444645a
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
2 changed files with 17 additions and 13 deletions

View File

@ -22,6 +22,7 @@ import me.kavin.piped.utils.resp.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.hibernate.Session;
import org.hibernate.StatelessSession;
import org.jetbrains.annotations.NotNull;
import org.xml.sax.InputSource;
@ -72,8 +73,10 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
Multithreading.runAsync(() -> {
for (var entry : feed.getEntries()) {
String url = entry.getLinks().get(0).getHref();
if (DatabaseHelper.getVideoFromId(StringUtils.substring(url, -11)) != null)
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
if (DatabaseHelper.doesVideoExist(s, StringUtils.substring(url, -11)))
continue;
}
VideoHelpers.handleNewVideo(url, entry.getPublishedDate().getTime(), null);
}
});

View File

@ -43,22 +43,23 @@ public class VideoHelpers {
long infoTime = info.getUploadDate() != null ? info.getUploadDate().offsetDateTime().toInstant().toEpochMilli()
: System.currentTimeMillis();
Video video = null;
if (channel != null && (video = DatabaseHelper.getVideoFromId(info.getId())) == null
if (channel != null
&& (System.currentTimeMillis() - infoTime) < TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION)) {
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
if (!DatabaseHelper.doesVideoExist(s, info.getId())) {
video = new Video(info.getId(), info.getName(), info.getViewCount(), info.getDuration(),
Video video = new Video(info.getId(), info.getName(), info.getViewCount(), info.getDuration(),
Math.max(infoTime, time), info.getThumbnailUrl(), info.isShortFormContent(), channel);
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
var tr = s.beginTransaction();
s.insert(video);
tr.commit();
return;
}
}
} else if (video != null) {
updateVideo(info.getId(), info, time);
}
}