Skip to content

Commit

Permalink
feat: pgsql (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 authored Oct 12, 2024
1 parent 81c5dbe commit 10b42ea
Show file tree
Hide file tree
Showing 27 changed files with 123 additions and 118 deletions.
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mariadb
DB_HOST=systemd-hub-mariadb
DB_PORT=3306
DB_CONNECTION=pgsql
DB_HOST=systemd-hub-pgsql
DB_PORT=5432
DB_DATABASE=hub
DB_USERNAME=user
DB_PASSWORD=password
DB_PASSWORD=secret

SESSION_DRIVER=redis
SESSION_LIFETIME=604800
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ Please note it's a low-tier VPS, expect slowness. :)

## Details

Hub has been build using the following stack:
Hub uses the following stack:

- [nginx-vod-module (main)](https://github.com/kaltura/nginx-vod-module)
- [Laravel 11.x](https://laravel.com/)
- [Livewire 3.x](https://livewire.laravel.com/)
- [PostgreSQL 17.x](https://www.postgresql.org/)
- [Podman 5.x](https://podman.io/)
- [Meilisearch 1.x](https://www.meilisearch.com/)

Expand Down
3 changes: 2 additions & 1 deletion config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@

'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'root' => storage_path('app/private'),
'serve' => true,
'throw' => true,
],

Expand Down
7 changes: 7 additions & 0 deletions docs/podman/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ cd ~/projects/hub
./docs/podman/make
```

To rebuild with no-cache (or any other args):

```bash
cd ~/projects/hub
./docs/podman/make --no-cache
```

### Systemd units

Copy the `systemd` directory to `~/.config/containers`, verify the path `~/.config/containers/systemd/hub` exists.
Expand Down
4 changes: 2 additions & 2 deletions docs/podman/containers/systemd/hub/config/app.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
UID=1000
GID=1000
PATH=/home/username/projects/hub
IMPORT_PATH=/mnt/x/videos/import
APP_PATH=/home/username/projects/hub
IMPORT_PATH=/mnt/storage/videos/import
MEDIA_PATH=/mnt/data/projects/hub/media
6 changes: 0 additions & 6 deletions docs/podman/containers/systemd/hub/config/mariadb.env

This file was deleted.

4 changes: 4 additions & 0 deletions docs/podman/containers/systemd/hub/config/postgres.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PGPASSWORD=secret
POSTGRES_DB=hub
POSTGRES_USER=user
POSTGRES_PASSWORD=password
6 changes: 3 additions & 3 deletions docs/podman/containers/systemd/hub/hub-app.container
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=App container
Requires=traefik.service hub-redis.service hub-mariadb.service hub-meilisearch.service hub-mailpit.service hub-minio.service
After=traefik.service hub-redis.service hub-mariadb.service hub-meilisearch.service hub-mailpit.service hub-minio.service
Requires=traefik.service hub-redis.service hub-pgsql.service hub-meilisearch.service hub-mailpit.service hub-minio.service
After=traefik.service hub-redis.service hub-pgsql.service hub-meilisearch.service hub-mailpit.service hub-minio.service

[Service]
EnvironmentFile=%h/.config/containers/systemd/hub/config/app.env
Expand All @@ -13,7 +13,7 @@ Image=localhost/hub-app:latest
AutoUpdate=local
EnvironmentFile=%h/.config/containers/systemd/hub/config/dev.env
LogDriver=none
Volume=${PATH}:/app:rw,z
Volume=${APP_PATH}:/app:rw,z
Volume=${IMPORT_PATH}:/app/storage/app/import:rw,z
Volume=${MEDIA_PATH}:/app/storage/app/media:rw,z
Secret=tlscert,target=/run/secrets/cert.pem,uid=${UID},gid=${GID}
Expand Down
17 changes: 0 additions & 17 deletions docs/podman/containers/systemd/hub/hub-mariadb.container

This file was deleted.

18 changes: 18 additions & 0 deletions docs/podman/containers/systemd/hub/hub-pgsql.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=PostgreSQL container

[Service]
Restart=always

[Container]
Image=docker.io/library/postgres:latest
AutoUpdate=registry
EnvironmentFile=%h/.config/containers/systemd/hub/config/postgres.env
LogDriver=none
ShmSize=100m
Volume=hub-pgsql:/var/lib/postgresql/data:rw,Z,U
Network=hub.network
PublishPort=5432:5432

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion docs/podman/containers/systemd/hub/hub.container
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Restart=always
Image=localhost/hub-nginx:latest
AutoUpdate=local
EnvironmentFile=%h/.config/containers/systemd/hub/config/nginx.env
Volume=${PATH}:/app:ro,z
Volume=${APP_PATH}:/app:ro,z
Volume=${MEDIA_PATH}:/app/storage/app/media:ro,z
User=${UID}
Group=${GID}
Expand Down
7 changes: 3 additions & 4 deletions docs/podman/images/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ RUN apk add --no-cache --virtual .run-deps \
libvorbis \
libvpx \
libwebp \
mariadb-client \
minio-client \
npm \
numactl \
opencore-amr \
openjpeg \
optipng \
pngquant \
speex \
minio-client \
postgresql-client \
sqlite \
supervisor \
tzdata \
Expand Down Expand Up @@ -85,12 +85,11 @@ RUN install-php-extensions \
imap \
intl \
msgpack \
mysqli \
opcache \
openswoole \
pcntl \
pcov \
pdo_mysql \
pdo_pgsql \
redis \
uv \
zip
Expand Down
2 changes: 1 addition & 1 deletion resources/views/app/lists/tag/view.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@php
$items = Number::abbreviate($tag->videos_count);
$items = Number::abbreviate($tag->videos()->count());
@endphp

{{ html()
Expand Down
2 changes: 0 additions & 2 deletions src/App/Web/Lists/Components/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ protected function getPageItems(?int $page = null): LengthAwarePaginator
$page ??= $this->getPage();

return $this->getQuery()
->withCount('videos')
->type($this->type)
->orderByDesc('videos_count')
->paginate(perPage: 9, page: $page);
}

Expand Down
11 changes: 3 additions & 8 deletions src/App/Web/Tags/Forms/RelatedForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace App\Web\Tags\Forms;

use Domain\Tags\Actions\GetPopularTags;
use Domain\Tags\Models\Tag;
use Foxws\WireUse\Forms\Support\Form;
use Illuminate\Support\Collection;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Validate;

class RelatedForm extends Form
Expand Down Expand Up @@ -34,13 +34,8 @@ public function query(): string
->value();
}

#[Computed(cache: true, key: 'popular-tags')]
public function popular(): Collection
protected function popular(): Collection
{
return Tag::query()
->withCount('videos')
->orderByDesc('videos_count')
->take(16)
->get();
return app(GetPopularTags::class)->execute()->take(16);
}
}
13 changes: 3 additions & 10 deletions src/App/Web/Videos/Components/Favorites.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,23 @@ public function boot(): void
$this->authorize('view', $this->getPlaylist());
}

#[Computed(persist: true)]
#[Computed(persist: true, seconds: 60 * 20)]
public function items(): Collection
{
return $this->getPlaylist()
->videos()
->published()
->randomSeed('videos-favorites', 60 * 10)
->orderByDesc('videoables.updated_at')
->take(24)
->get();
}

public function refresh(): void
{
unset($this->items);

$this->dispatch('$refresh');
}

protected function getTitle(): ?string
{
return __('Favorites');
}

protected function getPlaylist(): Playlist
protected function getPlaylist(): ?Playlist
{
return $this->getAuthModel()->playlists()->favorites();
}
Expand Down
2 changes: 1 addition & 1 deletion src/App/Web/Videos/Components/Next.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Next extends Section
{
use WithVideo;

#[Computed]
#[Computed(persist: true, seconds: 60 * 20)]
public function items(): Collection
{
return app(GetSimilarVideos::class)->execute($this->getVideo(), limit: 24)->collect();
Expand Down
5 changes: 3 additions & 2 deletions src/App/Web/Videos/Components/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ class Random extends Section
{
use WithVideo;

#[Computed(persist: true)]
#[Computed(persist: true, seconds: 60 * 20)]
public function items(): Collection
{
return $this->getQuery()
->random()
->whereKeyNot($this->getVideoKey())
->published()
->feed()
->take(24)
->get();
}
Expand Down
5 changes: 3 additions & 2 deletions src/App/Web/Videos/Components/Recently.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

class Recently extends Section
{
#[Computed(persist: true)]
#[Computed(persist: true, seconds: 60 * 20)]
public function items(): Collection
{
return $this->getQuery()
->latest()
->published()
->recent()
->take(24)
->get();
}
Expand Down
5 changes: 3 additions & 2 deletions src/App/Web/Videos/Components/Recommended.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

class Recommended extends Section
{
#[Computed(persist: true)]
#[Computed(persist: true, seconds: 60 * 20)]
public function items(): Collection
{
return $this->getQuery()
->recommended()
->published()
->feed()
->take(24)
->get();
}
Expand Down
12 changes: 3 additions & 9 deletions src/App/Web/Videos/Components/Watching.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,17 @@ public function boot(): void
$this->authorize('view', $this->getPlaylist());
}

#[Computed(persist: true)]
#[Computed(persist: true, seconds: 60 * 20)]
public function items(): Collection
{
return $this->getPlaylist()->videos()
return $this->getPlaylist()
->videos()
->published()
->orderByDesc('videoables.updated_at')
->take(24)
->get();
}

public function refresh(): void
{
unset($this->items);

$this->dispatch('$refresh');
}

protected function getTitle(): ?string
{
return __('Continue Watching');
Expand Down
11 changes: 2 additions & 9 deletions src/App/Web/Videos/Components/Watchlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,17 @@ public function boot(): void
$this->authorize('view', $this->getPlaylist());
}

#[Computed(persist: true)]
#[Computed(persist: true, seconds: 60 * 20)]
public function items(): Collection
{
return $this->getPlaylist()
->videos()
->published()
->randomSeed('videos-watchlist', 60 * 10)
->orderByDesc('videoables.updated_at')
->take(24)
->get();
}

public function refresh(): void
{
unset($this->items);

$this->dispatch('$refresh');
}

protected function getTitle(): ?string
{
return __('On Watchlist');
Expand Down
13 changes: 5 additions & 8 deletions src/App/Web/Videos/Forms/TagsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace App\Web\Videos\Forms;

use Domain\Tags\Actions\GetPopularTags;
use Domain\Tags\Models\Tag;
use Foxws\WireUse\Forms\Support\Form;
use Illuminate\Support\Collection;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Validate;

class TagsForm extends Form
Expand Down Expand Up @@ -34,13 +34,10 @@ public function query(): string
->value();
}

#[Computed(persist: true)]
public function popular(): Collection
protected function popular(): Collection
{
return Tag::query()
->withCount('videos')
->orderByDesc('videos_count')
->take(16)
->get();
$items = app()->make(GetPopularTags::class)->execute();

return $items->take(16);
}
}
Loading

0 comments on commit 10b42ea

Please sign in to comment.