mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-12-14 14:20:29 +05:30
Add index and improve pubsub db query.
This commit is contained in:
parent
376e068264
commit
6ec517e0ef
@ -34,12 +34,9 @@ public class Main {
|
|||||||
Session s = DatabaseSessionFactory.createSession();
|
Session s = DatabaseSessionFactory.createSession();
|
||||||
|
|
||||||
List<PubSub> pubSubList = s.createNativeQuery(
|
List<PubSub> pubSubList = s.createNativeQuery(
|
||||||
"select distinct pubsub.* from pubsub inner join users_subscribed on pubsub.id = users_subscribed.channel",
|
"select distinct pubsub.* from pubsub inner join users_subscribed on pubsub.id = users_subscribed.channel where pubsub.subbed_at < :time",
|
||||||
PubSub.class).getResultList();
|
PubSub.class).setParameter("time", System.currentTimeMillis() - TimeUnit.DAYS.toMillis(4))
|
||||||
|
.getResultList();
|
||||||
pubSubList.removeIf(pubsub -> {
|
|
||||||
return System.currentTimeMillis() - pubsub.getSubbedAt() < TimeUnit.DAYS.toMillis(4);
|
|
||||||
});
|
|
||||||
|
|
||||||
Collections.shuffle(pubSubList);
|
Collections.shuffle(pubSubList);
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ import javax.persistence.Index;
|
|||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "pubsub", indexes = { @Index(columnList = "id", name = "pubsub_id_idx") })
|
@Table(name = "pubsub", indexes = { @Index(columnList = "id", name = "pubsub_id_idx"),
|
||||||
|
@Index(columnList = "subbed_at", name = "pubsub_subbed_at_idx") })
|
||||||
public class PubSub {
|
public class PubSub {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
Loading…
Reference in New Issue
Block a user