Skip to content

Commit f11e33f

Browse files
committed
refactor(database): remove pagination and performance controllers, streamline base controller
- Deleted the PaginationController and PerformanceController to simplify the database controller structure. - Updated BaseController to eliminate lazy initialization for pagination and performance, reducing overhead. - Adjusted documentation and related references to reflect the removal of pagination functionality.
1 parent b3cf6df commit f11e33f

File tree

7 files changed

+8
-621
lines changed

7 files changed

+8
-621
lines changed

.cursor/rules/database/controllers.mdc

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ BaseController uses **composition** to provide specialized database operations:
2020

2121
#### Specialized Controllers (Lazy Loaded)
2222

23-
- **PaginationController**: Paginated results with metadata
2423
- **BulkOperationsController**: Batch operations for efficiency
2524
- **TransactionController**: Transaction management
2625
- **UpsertController**: Get-or-create and upsert patterns
27-
- **PerformanceController**: Query optimization and analysis
2826

2927
### Lazy Initialization Strategy
3028

@@ -116,30 +114,6 @@ class UserController(BaseController[User]):
116114
return await self.with_transaction(operation)
117115
```
118116

119-
### Pagination Patterns
120-
121-
**Use pagination for large result sets:**
122-
123-
```python
124-
# Simple pagination
125-
result = await controller.paginate(page=1, per_page=20)
126-
127-
# With filters and ordering
128-
result = await controller.paginate(
129-
page=1,
130-
per_page=20,
131-
filters={"active": True},
132-
order_by=User.created_at.desc()
133-
)
134-
135-
# Access pagination metadata
136-
users = result.items
137-
total = result.total
138-
pages = result.pages
139-
has_next = result.has_next
140-
has_prev = result.has_prev
141-
```
142-
143117
### Bulk Operations
144118

145119
**Efficient batch processing:**
@@ -304,20 +278,12 @@ class GuildController(BaseController[Guild]):
304278

305279
**When to use:**
306280

307-
- Pagination for large datasets
308281
- Bulk operations for efficiency
309282
- Upsert for synchronization
310283
- Transactions for consistency
311284

312285
### Leverage Specialized Controllers for Optimized Queries
313286

314-
**Pagination:**
315-
316-
```python
317-
# For UI display with metadata
318-
result = await controller.paginate(page=1, per_page=20)
319-
```
320-
321287
**Bulk operations:**
322288

323289
```python
@@ -450,14 +416,14 @@ users = await controller.find_all_with_options(
450416
)
451417
```
452418

453-
### ❌ Ignoring Pagination for Large Datasets
419+
### ❌ Loading All Records for Large Datasets
454420

455421
```python
456-
# BAD: Loading all records
422+
# BAD: Loading all records without limit
457423
users = await controller.find_all() # Could be thousands
458424

459-
# GOOD: Use pagination
460-
result = await controller.paginate(page=1, per_page=20)
425+
# GOOD: Use limit and offset for pagination
426+
users = await controller.find_all(filters={"active": True}, limit=20, offset=0)
461427
```
462428

463429
## Related Rules

docs/content/developer/concepts/database/controllers.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ The BaseController uses composition to provide specialized database operations t
2929

3030
#### Specialized Controllers (Lazy Loaded)
3131

32-
- **PaginationController**: Paginated results with metadata
3332
- **BulkOperationsController**: Batch operations for efficiency
3433
- **TransactionController**: Transaction management
3534
- **UpsertController**: Get-or-create and upsert patterns
36-
- **PerformanceController**: Query optimization and analysis
3735

3836
### Lazy Initialization Strategy
3937

@@ -81,7 +79,7 @@ Create domain-specific controllers that extend BaseController with business logi
8179

8280
### Specialized Controller Usage
8381

84-
Leverage pagination for large datasets, bulk operations for efficiency, upsert for synchronization, and transactions for consistency.
82+
Leverage bulk operations for efficiency, upsert for synchronization, and transactions for consistency.
8583

8684
## Best Practices
8785

@@ -106,7 +104,6 @@ Build domain-specific controllers that encapsulate business rules and provide hi
106104

107105
### Leverage Specialized Controllers for Optimized Queries
108106

109-
- Pagination for large result sets and UI display
110107
- Bulk operations for batch processing efficiency
111108
- Upsert for data synchronization scenarios
112109
- Transactions for multi-step operations requiring consistency

src/tux/database/controllers/base/base_controller.py

Lines changed: 2 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
from .bulk import BulkOperationsController
1111
from .crud import CrudController
12-
from .pagination import PaginationController, PaginationResult
13-
from .performance import PerformanceController
1412
from .query import QueryController
1513
from .transaction import TransactionController
1614
from .upsert import UpsertController
@@ -26,8 +24,8 @@ class BaseController[ModelT]:
2624
This controller delegates operations to specialized controllers while
2725
maintaining backward compatibility with the original BaseController API.
2826
Core CRUD and Query controllers are eagerly initialized, while specialized
29-
controllers (pagination, bulk, transaction, performance, upsert) use lazy
30-
initialization to reduce overhead for simple use cases.
27+
controllers (bulk, transaction, upsert) use lazy initialization to reduce
28+
overhead for simple use cases.
3129
"""
3230

3331
def __init__(self, model: type[ModelT], db: DatabaseService | None = None) -> None:
@@ -59,10 +57,8 @@ def __init__(self, model: type[ModelT], db: DatabaseService | None = None) -> No
5957
self._query = QueryController(model, db)
6058

6159
# Specialized controllers - lazy initialization (reduces overhead)
62-
self._pagination: PaginationController[ModelT] | None = None
6360
self._bulk: BulkOperationsController[ModelT] | None = None
6461
self._transaction: TransactionController[ModelT] | None = None
65-
self._performance: PerformanceController[ModelT] | None = None
6662
self._upsert: UpsertController[ModelT] | None = None
6763

6864
# Properties for test compatibility
@@ -91,19 +87,6 @@ def model_class(self) -> type[ModelT]:
9187
return self.model
9288

9389
# Lazy initialization helpers
94-
def _get_pagination(self) -> PaginationController[ModelT]:
95-
"""
96-
Get or create pagination controller.
97-
98-
Returns
99-
-------
100-
PaginationController[ModelT]
101-
The pagination controller instance.
102-
"""
103-
if self._pagination is None:
104-
self._pagination = PaginationController(self.model, self.db)
105-
return self._pagination
106-
10790
def _get_bulk(self) -> BulkOperationsController[ModelT]:
10891
"""
10992
Get or create bulk operations controller.
@@ -130,19 +113,6 @@ def _get_transaction(self) -> TransactionController[ModelT]:
130113
self._transaction = TransactionController(self.model, self.db)
131114
return self._transaction
132115

133-
def _get_performance(self) -> PerformanceController[ModelT]:
134-
"""
135-
Get or create performance controller.
136-
137-
Returns
138-
-------
139-
PerformanceController[ModelT]
140-
The performance controller instance.
141-
"""
142-
if self._performance is None:
143-
self._performance = PerformanceController(self.model, self.db)
144-
return self._performance
145-
146116
def _get_upsert(self) -> UpsertController[ModelT]:
147117
"""
148118
Get or create upsert controller.
@@ -312,109 +282,6 @@ async def execute_query(self, query: Any) -> Any:
312282
"""
313283
return await self._query.execute_query(query)
314284

315-
async def find_with_json_query(
316-
self,
317-
json_column: str,
318-
json_path: str,
319-
value: Any,
320-
filters: Any | None = None,
321-
) -> list[ModelT]:
322-
"""
323-
Find records using JSON column queries.
324-
325-
Returns
326-
-------
327-
list[ModelT]
328-
List of records matching the JSON query.
329-
"""
330-
return await self._query.find_with_json_query(
331-
json_column,
332-
json_path,
333-
value,
334-
filters,
335-
)
336-
337-
async def find_with_array_contains(
338-
self,
339-
array_column: str,
340-
value: Any,
341-
filters: Any | None = None,
342-
) -> list[ModelT]:
343-
"""
344-
Find records where array column contains value.
345-
346-
Returns
347-
-------
348-
list[ModelT]
349-
List of records with matching array values.
350-
"""
351-
return await self._query.find_with_array_contains(array_column, value, filters)
352-
353-
async def find_with_full_text_search(
354-
self,
355-
search_columns: list[str],
356-
search_term: str,
357-
filters: Any | None = None,
358-
) -> list[ModelT]:
359-
"""
360-
Find records using full-text search.
361-
362-
Returns
363-
-------
364-
list[ModelT]
365-
List of records matching the search term.
366-
"""
367-
return await self._query.find_with_full_text_search(
368-
search_columns,
369-
search_term,
370-
filters,
371-
)
372-
373-
# ------------------------------------------------------------------
374-
# Pagination Methods - Lazy-loaded
375-
# ------------------------------------------------------------------
376-
377-
async def paginate(
378-
self,
379-
page: int = 1,
380-
per_page: int = 20,
381-
filters: Any | None = None,
382-
order_by: Any | None = None,
383-
) -> PaginationResult[ModelT]:
384-
"""
385-
Paginate records with metadata.
386-
387-
Returns
388-
-------
389-
PaginationResult[ModelT]
390-
Pagination result with items, total, and page info.
391-
"""
392-
return await self._get_pagination().paginate(page, per_page, filters, order_by)
393-
394-
async def find_paginated(
395-
self,
396-
page: int = 1,
397-
per_page: int = 20,
398-
filters: Any | None = None,
399-
order_by: Any | None = None,
400-
load_relationships: list[str] | None = None,
401-
) -> PaginationResult[ModelT]:
402-
"""
403-
Find paginated records with relationship loading.
404-
405-
Returns
406-
-------
407-
PaginationResult[ModelT]
408-
Pagination result with items and relationships loaded.
409-
"""
410-
return await self._get_pagination().find_paginated(
411-
page,
412-
per_page,
413-
filters,
414-
order_by,
415-
load_relationships,
416-
)
417-
418285
# ------------------------------------------------------------------
419286
# Bulk Operations - Lazy-loaded
420287
# ------------------------------------------------------------------
@@ -474,26 +341,6 @@ async def delete_where(self, filters: Any) -> int:
474341
"""
475342
return await self._get_bulk().delete_where(filters)
476343

477-
async def bulk_upsert_with_conflict_resolution(
478-
self,
479-
items: list[dict[str, Any]],
480-
conflict_columns: list[str],
481-
update_columns: list[str] | None = None,
482-
) -> list[ModelT]:
483-
"""
484-
Bulk upsert with conflict resolution.
485-
486-
Returns
487-
-------
488-
list[ModelT]
489-
List of upserted records.
490-
"""
491-
return await self._get_bulk().bulk_upsert_with_conflict_resolution(
492-
items,
493-
conflict_columns,
494-
update_columns,
495-
)
496-
497344
# ------------------------------------------------------------------
498345
# Transaction Methods - Lazy-loaded
499346
# ------------------------------------------------------------------
@@ -531,41 +378,6 @@ async def execute_transaction(self, callback: Callable[[], Any]) -> Any:
531378
"""
532379
return await self._get_transaction().execute_transaction(callback)
533380

534-
# ------------------------------------------------------------------
535-
# Performance Methods - Lazy-loaded
536-
# ------------------------------------------------------------------
537-
538-
async def get_table_statistics(self) -> dict[str, Any]:
539-
"""
540-
Get comprehensive table statistics.
541-
542-
Returns
543-
-------
544-
dict[str, Any]
545-
Dictionary containing table statistics.
546-
"""
547-
return await self._get_performance().get_table_statistics()
548-
549-
async def explain_query_performance(
550-
self,
551-
query: Any,
552-
analyze: bool = False,
553-
buffers: bool = False,
554-
) -> dict[str, Any]:
555-
"""
556-
Explain query performance with optional analysis.
557-
558-
Returns
559-
-------
560-
dict[str, Any]
561-
Dictionary containing query execution plan and statistics.
562-
"""
563-
return await self._get_performance().explain_query_performance(
564-
query,
565-
analyze,
566-
buffers,
567-
)
568-
569381
# ------------------------------------------------------------------
570382
# Upsert Methods - Lazy-loaded
571383
# ------------------------------------------------------------------

0 commit comments

Comments
 (0)