mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
PubSub query improvements and fix for postgres.
This commit is contained in:
parent
c45b723135
commit
78d20b2519
10 changed files with 63 additions and 22 deletions
|
@ -6,3 +6,4 @@ Dockerfile
|
||||||
LICENSE
|
LICENSE
|
||||||
*.md
|
*.md
|
||||||
config.properties
|
config.properties
|
||||||
|
data/
|
||||||
|
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -15,6 +15,9 @@ bin/
|
||||||
### Gradle ###
|
### Gradle ###
|
||||||
/build/
|
/build/
|
||||||
|
|
||||||
|
# Database Data
|
||||||
|
/data/
|
||||||
|
|
||||||
# TxT File
|
# TxT File
|
||||||
*.txt
|
*.txt
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# The port to Listen on.
|
# The port to Listen on.
|
||||||
PORT: 8080
|
PORT: 8080
|
||||||
|
|
||||||
|
@ -11,3 +10,13 @@ PROXY_PART: https://pipedproxy-ams.kavin.rocks
|
||||||
# Captcha Parameters
|
# Captcha Parameters
|
||||||
CAPTCHA_BASE_URL: https://api.capmonster.cloud/
|
CAPTCHA_BASE_URL: https://api.capmonster.cloud/
|
||||||
CAPTCHA_API_KEY: INSERT_HERE
|
CAPTCHA_API_KEY: INSERT_HERE
|
||||||
|
|
||||||
|
# Public API URL
|
||||||
|
API_URL: https://pipedapi.kavin.rocks
|
||||||
|
|
||||||
|
# Hibernate properties
|
||||||
|
hibernate.connection.url: jdbc:postgresql://postgres:5432/piped
|
||||||
|
hibernate.connection.driver_class: org.postgresql.Driver
|
||||||
|
hibernate.dialect: org.hibernate.dialect.PostgreSQL10Dialect
|
||||||
|
hibernate.connection.username: piped
|
||||||
|
hibernate.connection.password: changeme
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
version: "3.8"
|
|
||||||
services:
|
services:
|
||||||
piped:
|
piped:
|
||||||
image: 1337kavin/piped:latest
|
image: 1337piped:latest
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8080:8080"
|
- "127.0.0.1:8080:8080"
|
||||||
volumes:
|
volumes:
|
||||||
- ./config.properties:/app/config.properties
|
- ./config.properties:/app/config.properties
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
||||||
|
postgres:
|
||||||
|
image: postgres:13-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- ./data/db:/var/lib/postgresql/data
|
||||||
|
environment:
|
||||||
|
- POSTGRES_DB=piped
|
||||||
|
- POSTGRES_USER=piped
|
||||||
|
- POSTGRES_PASSWORD=changeme
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package me.kavin.piped;
|
package me.kavin.piped;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
@ -35,6 +36,13 @@ public class Main {
|
||||||
|
|
||||||
List<String> channels = DatabaseHelper.getGlobalSubscribedChannelIds(s);
|
List<String> channels = DatabaseHelper.getGlobalSubscribedChannelIds(s);
|
||||||
|
|
||||||
|
DatabaseHelper.getPubSubFromIds(s, channels).forEach(pubsub -> {
|
||||||
|
if (System.currentTimeMillis() - pubsub.getSubbedAt() < TimeUnit.DAYS.toMillis(4))
|
||||||
|
channels.remove(pubsub.getId());
|
||||||
|
});
|
||||||
|
|
||||||
|
Collections.shuffle(channels);
|
||||||
|
|
||||||
for (String channelId : channels)
|
for (String channelId : channels)
|
||||||
Multithreading.runAsyncLimitedPubSub(() -> {
|
Multithreading.runAsyncLimitedPubSub(() -> {
|
||||||
Session sess = DatabaseSessionFactory.createSession();
|
Session sess = DatabaseSessionFactory.createSession();
|
||||||
|
|
|
@ -82,4 +82,13 @@ public class DatabaseHelper {
|
||||||
|
|
||||||
return s.createQuery(cr).uniqueResult();
|
return s.createQuery(cr).uniqueResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final List<PubSub> getPubSubFromIds(Session s, List<String> id) {
|
||||||
|
CriteriaBuilder cb = s.getCriteriaBuilder();
|
||||||
|
CriteriaQuery<PubSub> cr = cb.createQuery(PubSub.class);
|
||||||
|
Root<PubSub> root = cr.from(PubSub.class);
|
||||||
|
cr.select(root).where(root.get("id").in(id));
|
||||||
|
|
||||||
|
return s.createQuery(cr).getResultList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import javax.persistence.Index;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "channels", indexes = { @Index(columnList = "uploader_id", name = "uploader_id_idx") })
|
@Table(name = "channels", indexes = { @Index(columnList = "uploader_id", name = "channels_uploader_id_idx") })
|
||||||
public class Channel {
|
public class Channel {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|
|
@ -16,7 +16,7 @@ import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users", indexes = { @Index(columnList = "id", name = "id_idx"),
|
@Table(name = "users", indexes = { @Index(columnList = "id", name = "users_id_idx"),
|
||||||
@Index(columnList = "username", name = "username_idx") })
|
@Index(columnList = "username", name = "username_idx") })
|
||||||
public class User implements Serializable {
|
public class User implements Serializable {
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@ import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "videos", indexes = { @Index(columnList = "id", name = "id_idx"),
|
@Table(name = "videos", indexes = { @Index(columnList = "id", name = "videos_id_idx"),
|
||||||
@Index(columnList = "uploader_id", name = "uploader_id_idx") })
|
@Index(columnList = "uploader_id", name = "video_uploader_id_idx") })
|
||||||
public class Video {
|
public class Video {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|
|
@ -11,5 +11,6 @@
|
||||||
|
|
||||||
<property name="hibernate.connection.provider_class">org.hibernate.hikaricp.internal.HikariCPConnectionProvider</property>
|
<property name="hibernate.connection.provider_class">org.hibernate.hikaricp.internal.HikariCPConnectionProvider</property>
|
||||||
<property name="hibernate.connection.handling_mode">DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT</property>
|
<property name="hibernate.connection.handling_mode">DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT</property>
|
||||||
|
<property name="hibernate.jdbc.batch_size">50</property>
|
||||||
</session-factory>
|
</session-factory>
|
||||||
</hibernate-configuration>
|
</hibernate-configuration>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue