mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Don't query full video anywhere.
This commit is contained in:
parent
c2248a1bdc
commit
a15444645a
2 changed files with 17 additions and 13 deletions
|
@ -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)
|
||||
continue;
|
||||
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
|
||||
if (DatabaseHelper.doesVideoExist(s, StringUtils.substring(url, -11)))
|
||||
continue;
|
||||
}
|
||||
VideoHelpers.handleNewVideo(url, entry.getPublishedDate().getTime(), null);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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)) {
|
||||
|
||||
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();
|
||||
if (!DatabaseHelper.doesVideoExist(s, info.getId())) {
|
||||
|
||||
Video video = new Video(info.getId(), info.getName(), info.getViewCount(), info.getDuration(),
|
||||
Math.max(infoTime, time), info.getThumbnailUrl(), info.isShortFormContent(), channel);
|
||||
|
||||
var tr = s.beginTransaction();
|
||||
s.insert(video);
|
||||
tr.commit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (video != null) {
|
||||
updateVideo(info.getId(), info, time);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue