---
url: https://record-api-docs.vercel.app/guide/performance.md
---

# Performance

## Performance Optimization

### Database Optimization

```sql
-- Add indexes for better performance
CREATE INDEX idx_audit_logs_entity ON audit_logs(entity_type, entity_id);
CREATE INDEX idx_audit_logs_created_at ON audit_logs(created_at);
-- Optional (only if you enable multi-tenant mode and store tenant IDs in audit_logs)
-- CREATE INDEX idx_audit_logs_tenant_id ON audit_logs(tenant_id);
CREATE INDEX idx_users_email ON users(email);
```

### Caching Strategy

```php
// config/record.php
return [
    'cache' => [
        'enabled' => env('RECORD_API_CACHE_API', false),
        'ttl' => 3600,
        'prefix' => 'record_api',
        'per_table' => [],
    ],
];
```

### Queue Configuration

```bash
# Use Redis for better performance
QUEUE_CONNECTION=redis

# Configure queue workers
php artisan queue:work --queue=high,default --sleep=3 --tries=3 --max-time=3600
```

### Step 10: Configure Your Models (Optional)

To use the QueryHelpers trait in your models:

```php
use Mylekha\RecordApi\Traits\QueryHelpers;

class User extends Authenticatable
{
    use QueryHelpers;
    
    // Your model code
}
```

To implement audit logging in your models:

```php
use Mylekha\RecordApi\Traits\HasAuditQuery;
use Mylekha\RecordApi\Interfaces\AuditQueryInterface;

class User extends Authenticatable implements AuditQueryInterface
{
    use HasAuditQuery;
    
    public function getAuditEntityName(): string
    {
        return 'users';
    }
    
    public function getAuditEntityClass(): string
    {
        return static::class;
    }
}
```
