mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Add index and improve pubsub db query.
This commit is contained in:
parent
376e068264
commit
6ec517e0ef
2 changed files with 5 additions and 7 deletions
|
@ -34,12 +34,9 @@ public class Main {
|
|||
Session s = DatabaseSessionFactory.createSession();
|
||||
|
||||
List<PubSub> pubSubList = s.createNativeQuery(
|
||||
"select distinct pubsub.* from pubsub inner join users_subscribed on pubsub.id = users_subscribed.channel",
|
||||
PubSub.class).getResultList();
|
||||
|
||||
pubSubList.removeIf(pubsub -> {
|
||||
return System.currentTimeMillis() - pubsub.getSubbedAt() < TimeUnit.DAYS.toMillis(4);
|
||||
});
|
||||
"select distinct pubsub.* from pubsub inner join users_subscribed on pubsub.id = users_subscribed.channel where pubsub.subbed_at < :time",
|
||||
PubSub.class).setParameter("time", System.currentTimeMillis() - TimeUnit.DAYS.toMillis(4))
|
||||
.getResultList();
|
||||
|
||||
Collections.shuffle(pubSubList);
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ import javax.persistence.Index;
|
|||
import javax.persistence.Table;
|
||||
|
||||
@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 {
|
||||
|
||||
@Id
|
||||
|
|
Loading…
Reference in a new issue