Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Melhorias nas configurações #7

Merged
merged 12 commits into from
Aug 19, 2023
6 changes: 1 addition & 5 deletions app/Controller/PersonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ public function search(RequestInterface $request, ResponseInterface $response):
{
$term = $request->getQueryParams()['t'] ?? null;
if ($term) {
$list = Person::where(function (Builder $query) use ($term) {
$query->whereRaw("lower(name) like lower(\"%{$term}%\")")
->orWhereRaw("lower(nick) like lower(\"%{$term}%\")")
->orWhereRaw("lower(stack) like lower(\"%{$term}%\")");
})->limit(50)->get();
$list = Person::whereRaw('searchable like ?', [strtolower("%{$term}%")])->limit(50)->get();

return $response->json($list);
}
Expand Down
5 changes: 5 additions & 0 deletions app/Model/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class Person extends Model
'stack',
];

protected array $hidden = ['searchable'];

/**
* The attributes that should be cast to native types.
*/
protected array $casts = [
'id' => 'string',
'stack' => 'array'
Expand Down
1 change: 1 addition & 0 deletions app/Request/PersonRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function toPerson(): array
'name' => $data['nome'],
'birth' => $data['nascimento'],
'stack' => Json::encode($data['stack'] ?? null),
'searchable' => strtolower(join(" ", [$data['apelido'], $data['nome'], join(" ", $data['stack'] ?? [])]))
];
}
}
4 changes: 2 additions & 2 deletions config/autoload/databases.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
'prefix' => env('DB_PREFIX', ''),
'pool' => [
'min_connections' => 1,
'max_connections' => 10,
'max_connections' => 1000000,
'connect_timeout' => 10.0,
'wait_timeout' => 3.0,
'wait_timeout' => 10.0,
'heartbeat' => -1,
'max_idle_time' => (float) env('DB_MAX_IDLE_TIME', 60),
],
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ services:
deploy:
resources:
limits:
cpus: '0.5'
memory: '1.0GB'
cpus: '0.25'
memory: '0.7GB'

api2:
<<: *api
Expand All @@ -40,8 +40,8 @@ services:
deploy:
resources:
limits:
cpus: '0.15'
memory: '0.4GB'
cpus: '0.65'
memory: '1.0GB'

cache:
container_name: rinha-de-backend-cache
Expand Down
1 change: 1 addition & 0 deletions migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create table person(
id varchar(36) primary key unique,
nick varchar(32) not null,
name varchar(100) not null,
searchable longtext not null,
birth date not null,
stack json
);
Loading