PubSub query improvements and fix for postgres.

This commit is contained in:
FireMasterK 2021-07-17 03:25:55 +05:30
parent c45b723135
commit 78d20b2519
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
10 changed files with 63 additions and 22 deletions

View file

@ -6,3 +6,4 @@ Dockerfile
LICENSE LICENSE
*.md *.md
config.properties config.properties
data/

5
.gitignore vendored
View file

@ -15,8 +15,11 @@ bin/
### Gradle ### ### Gradle ###
/build/ /build/
# Database Data
/data/
# TxT File # TxT File
*.txt *.txt
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*

View file

@ -1,13 +1,22 @@
# The port to Listen on. # The port to Listen on.
PORT: 8080 PORT: 8080
# The number of workers to use for the server # The number of workers to use for the server
HTTP_WORKERS: 2 HTTP_WORKERS: 2
# Proxy
PROXY_PART: https://pipedproxy-ams.kavin.rocks
# Captcha Parameters # Proxy
CAPTCHA_BASE_URL: https://api.capmonster.cloud/ PROXY_PART: https://pipedproxy-ams.kavin.rocks
CAPTCHA_API_KEY: INSERT_HERE
# Captcha Parameters
CAPTCHA_BASE_URL: https://api.capmonster.cloud/
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

View file

@ -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

View file

@ -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();

View file

@ -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();
}
} }

View file

@ -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

View file

@ -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 {

View file

@ -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

View file

@ -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>