mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-12-13 22:00:29 +05:30
Use Criteria API for deleting old videos. (#302)
This commit is contained in:
parent
17b9a974de
commit
606cbf5ca6
@ -7,10 +7,10 @@ import me.kavin.piped.consts.Constants;
|
||||
import me.kavin.piped.utils.*;
|
||||
import me.kavin.piped.utils.obj.db.PubSub;
|
||||
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.hibernate.query.Query;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.localization.Localization;
|
||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeThrottlingDecrypter;
|
||||
@ -94,10 +94,14 @@ public class Main {
|
||||
public void run() {
|
||||
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||
|
||||
var cb = s.getCriteriaBuilder();
|
||||
var cd = cb.createCriteriaDelete(Video.class);
|
||||
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();
|
||||
|
||||
Query<?> query = s.createQuery("delete from Video where uploaded < :time").setParameter("time",
|
||||
System.currentTimeMillis() - TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION));
|
||||
var query = s.createMutationQuery(cd);
|
||||
|
||||
System.out.println(String.format("Cleanup: Removed %o old videos", query.executeUpdate()));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user