mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Cleanup transaction code. (#306)
This commit is contained in:
parent
7c087d82b3
commit
e6c0f7c0f4
2 changed files with 37 additions and 36 deletions
|
@ -10,7 +10,6 @@ import me.kavin.piped.utils.obj.db.User;
|
|||
import me.kavin.piped.utils.obj.db.Video;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.StatelessSession;
|
||||
import org.hibernate.Transaction;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.localization.Localization;
|
||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeThrottlingDecrypter;
|
||||
|
@ -99,7 +98,7 @@ public class Main {
|
|||
var root = cd.from(Video.class);
|
||||
cd.where(cb.lessThan(root.get("uploaded"), System.currentTimeMillis() - TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION)));
|
||||
|
||||
Transaction tr = s.beginTransaction();
|
||||
var tr = s.beginTransaction();
|
||||
|
||||
var query = s.createMutationQuery(cd);
|
||||
|
||||
|
|
|
@ -1325,7 +1325,7 @@ public class ResponseHelper {
|
|||
pvQuery.where(cb.not(pvRoot.get("id").in(subQuery)));
|
||||
|
||||
var tr = s.beginTransaction();
|
||||
s.createQuery(pvQuery).executeUpdate();
|
||||
s.createMutationQuery(pvQuery).executeUpdate();
|
||||
tr.commit();
|
||||
}
|
||||
}
|
||||
|
@ -1425,7 +1425,6 @@ public class ResponseHelper {
|
|||
if (!channelId.matches("[A-Za-z\\d_-]+"))
|
||||
return null;
|
||||
|
||||
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||
|
||||
final ChannelInfo info;
|
||||
|
||||
|
@ -1438,8 +1437,12 @@ public class ResponseHelper {
|
|||
|
||||
var channel = new me.kavin.piped.utils.obj.db.Channel(channelId, info.getName(),
|
||||
info.getAvatarUrl(), info.isVerified());
|
||||
|
||||
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||
var tr = s.beginTransaction();
|
||||
s.persist(channel);
|
||||
s.beginTransaction().commit();
|
||||
tr.commit();
|
||||
}
|
||||
|
||||
Multithreading.runAsync(() -> {
|
||||
try {
|
||||
|
@ -1461,7 +1464,6 @@ public class ResponseHelper {
|
|||
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
|
||||
public static void subscribePubSub(String channelId) throws IOException {
|
||||
|
||||
|
|
Loading…
Reference in a new issue