-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotesDanielGamboa.txt
193 lines (147 loc) · 8.37 KB
/
NotesDanielGamboa.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
Notes:
Edit php.ini in order to hangle larger file upload size.
upload_max_filesize = 36m
post_max_size = 36m
And published and edited App\Config\Livewire.php to hangle 36 Mb file uploads
The required field will be required conditionally depending on the outcome of the bool statement.
If true then it will be required
If false then it will not be required
TextInput::make('vat_number')
->required(fn (Get $get): bool => filled($get('company_name')))
Dependant drop down from another dropdown
Select::make('sub_category')
->options(fn (Get $get): array => match ($get('category')) {
'web' => [
'frontend_web' => 'Frontend development',
'backend_web' => 'Backend development',
],
'mobile' => [
'ios_mobile' => 'iOS development',
'android_mobile' => 'Android development',
],
'design' => [
'app_design' => 'Panel design',
'marketing_website_design' => 'Marketing website design',
],
default => [],
For media upload
This will create a sim link from public -> storage to the private Storage folder in order not to expose the file to the public forlder
Also edit env to have the exact url loke localhost:8000 or FQDN
php artisan storage:link
Installed Spatie Media Library plugin for filament.
composer require filament/spatie-laravel-media-library-plugin:"^3.1" -W
//This next comand as of today does not work properly
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="medialibrary-migrations"
// Currently the correct comand is
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="migrations"
Server side:
Get latest version of Sistema Ventas from GitHub
In workind directory /var/www/SistemaVentas/SistemaVentas
sudo git fetch https://github.com/DanielGamboa/SistemaVentas.git
Merge to server files and updates
sudo git reset --hard FETCH_HEAD
Get latest commit from log on local server
git log -1
Get latest commit from log on GitHub
git ls-remote https://github.com/DanielGamboa/SistemaVentas.git
Confirm same commit number to ensure they are on the same version.
Server side / Local development
On server side "sudo" privilages must be used in the root directory /var/www/SistemaVentas/SistemaVentas
Cache:
composer dump-autoload
php artisan config:cache
php artisan route:cache
php artisan view:cache
Note if cache was implemented caching will resume automatically after cache is cleared.
Each command clears part of the cache. None of these clear all cache on their own
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear
Implementing Cache:
There are two main ways to implement "cache" in a laravel filament proyect. The simple one is to add caching to the ModelResource file
and adding:
Cache::forget('table_name');
On the Filament\Resource\Page for CreateModel and EditModel.
The problem with this aproach is that if the Model record is modified or created by another part of the the APP or manually.
it will not clear the cache.
Therefore i have implemented laravel App\Listeners\ and hooked it into App\Providers\EventServiceProvider.php
php artisan make:listener ClearModelCache ---> Ej: ClearUserCache
Navigate to App\Listeners\ClearModelCache
Import:
use Illuminate\Support\Facades\Cache;
Add:
This code will excecute a cache clear comand for the corresponding db table
In this case the model is User, the db table is "users" (plural).
We will now execute this code from the event service provider for each event that requieres a cache clear in order for the program
to operate properly.
public function handle(object $event): void
{
//
Cache::forget('users');
}
Once this file is edited and Facades Cahce is imported. Open the EventServiceProvider:
---> Important, because in this example we will be calling the ClearModelCache when a User model record is created or edited.
Because we are using the full relative path it does not need to be imported.
'App\Listeners\ClearModelCache'
The listener event is targeting the 'eloquent.created'
For App\User model
And it accepts and array of values.
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
// Created a listener for the User model
'eloquent.created: App\User' => [
'App\Listeners\ClearUserCache',
],
// Updated a listener for the User model
'eloquent.updated: App\User' => [
'App\Listeners\ClearUserCache',
],
],
];`
The benefit of this aproach is that any update to the database will clear and update the cache with any DB modification. Further more it
will not clear all cache. It will only target specific a specific cache when needed.
https://www.youtube.com/watch?v=-NOOqIYEFwc might be outdated --- need to research
NEXT STEPS FOR PERFORMANCE OPTIMIZATION ---> Install and configure Redis Server, MUST HARDEN WARNING MUST HARDEN EXPLOITABLE + FIERWALL CONFIGURATION
https://redis.io/docs/install/install-redis/ --> INSTALL
https://redis.io/docs/management/ -----> CONFIGURE AND MANAGE
Finished WhatsApp template. Needs to be polished befor cache is implemented. Moving on for now
In order to improve DB responses each Instance should be about 1 gb because of overhead.
In my use case this should not be a problem as DB should not be very large in general.
I feel if mysql is provisioned to hold a max of 500 Mb creating pools with 600 Mb of ram should be ok for each instance.
Also, a thread should be available to mysql for each instance of the innodb_buffer_pool_instances.
So, for 30 users we could think about 5 threads (vcores) and about 5 * 600 Mb = 3 Gb of ram at least. Preferably 4
Plus added server cores and or threads.
ou can set the innodb_buffer_pool_size and innodb_buffer_pool_instances in your MySQL configuration file (usually my.cnf or my.ini), which is typically located in the MySQL installation directory.
For mysql on ubuntu:
On Ubuntu, the MySQL configuration file is typically named my.cnf and can be found at one of the following locations:
/etc/mysql/my.cnf
/etc/my.cnf
~/.my.cnf
[mysqld]
innodb_buffer_pool_size = 6G
innodb_buffer_pool_instances = 4
sudo service mysql restart
Server Side:
Configure .env and database:
Configure DB
CREATE DATABASE sistemaventasdb;
Create DB user with read and write permisions on local host and asign permisions.
CREATE USER 'libertydbuser'@'127.0.0.1' IDENTIFIED BY 'CaracasConcordCaracasMirafloresSantaAna9783696018!';
CREATE USER 'libertydbuser'@'localhost' IDENTIFIED BY 'CaracasConcordCaracasMirafloresSantaAna9783696018!';
GRANT ALL ON sistemaventadb.* TO 'libertydbuser'@'localhost';
GRANT ALL ON sistemaventasdb.* TO 'libertydbuser'@'127.0.0.1';
FLUSH PRIVILEGES;
EXIT;
Condigure .env key
sudo php artisan key:generate
sudo nano .env
Fill out .env fields for database:
db_databse: sistemaventadb
db_username: libertydbuser
db_password: CaracasConcordCaracasMirafloresSantaAna9783696018!
Configure apache2 permisions for laravel proyect
sudo chown -R www-data:www-data /var/www/html/liberty
sudo chmod -R 755 /var/www/html/liberty/SistemaVentas/storage
sudo chmod -R 755 /var/www/html/liberty/SistemaVentas/bootstrap/cache