https://github.com/rajahlone/peertuberandomsorttrick
trick to add local video list random sort, using originallyPublishedAt column
https://github.com/rajahlone/peertuberandomsorttrick
peertube postgresql
Last synced: 7 months ago
JSON representation
trick to add local video list random sort, using originallyPublishedAt column
- Host: GitHub
- URL: https://github.com/rajahlone/peertuberandomsorttrick
- Owner: RajahLone
- Created: 2025-02-04T20:21:04.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2025-02-04T21:39:39.000Z (9 months ago)
- Last Synced: 2025-02-12T10:25:00.190Z (9 months ago)
- Topics: peertube, postgresql
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# peertubeRandomSortTrick
- peertube has not (yet) a random sort feature for the local videos list.
- this trick adds local videos list random sort, using originallyPublishedAt field/column.
- modification is only in the postgresql database.
- uses pg_cron to randomize order in the video list regularly.
## Create a function in the database for random timestamps
```
su
psql
=# CREATE OR REPLACE FUNCTION get_unsorted() RETURNS TIMESTAMP as $$ SELECT random() * ('2020-02-01 00:00:00'::timestamp - '1980-01-01 00:00:00'::timestamp) + '1980-01-01 00:00:00'::timestamp $$ language sql;
=# GRANT EXECUTE ON FUNCTION get_unsorted TO postgres;
=# GRANT EXECUTE ON FUNCTION get_unsorted TO ;
=# UPDATE video SET "originallyPublishedAt" = get_unsorted()::timestamp;
```
So now sorting by 'original published date' will display local videos randomly.
With the peertube plugin 'sort-originally-published-at', this random sort can be by default.
## Reorder randomly every 10 minutes
```
sudo apt-get -y install postgresql-11-cron
su
psql
=# CREATE EXTENSION pg_cron;
=# SELECT cron.schedule('*/10 * * * *', $$update video set "originallyPublishedAt" = get_unsorted()::timestamp$$);
```
There may be credential issues. Look in /var/log/postgresql/ if the job is currently running good.
If not, try:
- to replace 'peer' by 'trust' in your pg_hba.conf
- UPDATE cron.job SET nodename = ''; -- in psql as postgres or user.