Commit Graph

8 Commits

Author SHA1 Message Date
Claude
dc0d72c896 feat: Add caching layer and batch operations for improved performance
Implement Phase 3 improvements: intelligent caching and batch operations
to significantly enhance SDK performance and usability.

**1. Caching Layer Implementation**

Added complete caching infrastructure with LRU eviction and TTL support:

- `wikijs/cache/base.py`: Abstract BaseCache interface with CacheKey structure
- `wikijs/cache/memory.py`: MemoryCache implementation with:
  * LRU (Least Recently Used) eviction policy
  * Configurable TTL (time-to-live) expiration
  * Cache statistics (hits, misses, hit rate)
  * Resource-specific invalidation
  * Automatic cleanup of expired entries

**Cache Integration:**
- Modified `WikiJSClient` to accept optional `cache` parameter
- Integrated caching into `PagesEndpoint.get()`:
  * Check cache before API request
  * Store successful responses in cache
  * Invalidate cache on write operations (update, delete)

**2. Batch Operations**

Added efficient batch methods to Pages API:

- `create_many(pages_data)`: Batch create multiple pages
- `update_many(updates)`: Batch update pages with partial success handling
- `delete_many(page_ids)`: Batch delete with detailed error reporting

All batch methods include:
- Partial success support (continue on errors)
- Detailed error tracking with indices
- Comprehensive error messages

**3. Comprehensive Testing**

Added 27 new tests (all passing):

- `tests/test_cache.py`: 17 tests for caching (99% coverage)
  * CacheKey string generation
  * TTL expiration
  * LRU eviction policy
  * Cache invalidation (specific & all resources)
  * Statistics tracking

- `tests/endpoints/test_pages_batch.py`: 10 tests for batch operations
  * Successful batch creates/updates/deletes
  * Partial failure handling
  * Empty list edge cases
  * Validation error handling

**Performance Benefits:**
- Caching reduces API calls for frequently accessed pages
- Batch operations reduce network overhead for bulk actions
- Configurable cache size and TTL for optimization

**Example Usage:**

```python
from wikijs import WikiJSClient
from wikijs.cache import MemoryCache

# Enable caching
cache = MemoryCache(ttl=300, max_size=1000)
client = WikiJSClient('https://wiki.example.com', auth='key', cache=cache)

# Cached GET requests
page = client.pages.get(123)  # Fetches from API
page = client.pages.get(123)  # Returns from cache

# Batch operations
pages = client.pages.create_many([
    PageCreate(title="Page 1", path="page-1", content="Content 1"),
    PageCreate(title="Page 2", path="page-2", content="Content 2"),
])

updates = client.pages.update_many([
    {"id": 1, "content": "Updated content"},
    {"id": 2, "is_published": False},
])

result = client.pages.delete_many([1, 2, 3])
print(f"Deleted {result['successful']} pages")
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-23 14:46:58 +00:00
Claude
8e9bd5973a Add comprehensive Assets API tests - increase coverage from 43% to 81%
Add 19 new tests for Assets endpoint covering:

Move operations:
- test_move_asset (success case)
- test_move_asset_validation_error (edge cases)

Folder operations:
- test_create_folder (full params)
- test_create_folder_minimal (minimal params)
- test_create_folder_validation_error
- test_delete_folder (success)
- test_delete_folder_validation_error

List operations with filters:
- test_list_assets_with_folder_filter
- test_list_assets_with_kind_filter
- test_list_assets_empty

Error handling:
- test_get_asset_not_found
- test_delete_asset_failure
- test_rename_asset_failure
- test_move_asset_failure
- test_create_folder_failure
- test_delete_folder_failure

Pagination & edge cases:
- test_iter_all_assets (pagination iterator)
- test_normalize_asset_data_minimal
- test_list_folders_empty

Impact:
- Assets endpoint: 43% → 81% coverage (+38%)
- Total tests: 423 → 442 tests (+19)
- Overall coverage: 77.10% → 79.32% (+2.22%)
- All tests passing (442/442)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-23 01:59:14 +00:00
Claude
cbbf801d7c Add comprehensive tests for Assets API (14 tests)
Tests include:
- Asset model validation (8 tests)
  - Asset, AssetRename, FolderCreate models
  - Field validation, filename validation
  - Size helper methods (size_mb, size_kb)
  - Slug normalization

- Sync AssetsEndpoint (6 tests)
  - List, get, rename, delete operations
  - Folder listing
  - Validation error handling

All 14 tests passing. Achieves comprehensive coverage for Assets API.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-22 20:36:01 +00:00
Claude
5c0de7f70b Add comprehensive tests for Groups API (24 tests)
Tests include:
- Group model validation (8 tests)
  - Group, GroupCreate, GroupUpdate models
  - Field validation, name validation
  - Minimal and full field tests

- Sync GroupsEndpoint (8 tests)
  - List, get, create, update, delete operations
  - User assignment/unassignment operations
  - Validation error handling

- Async AsyncGroupsEndpoint (8 tests)
  - Complete async coverage matching sync API
  - All CRUD operations tested
  - User management operations

All 24 tests passing. Achieves comprehensive coverage for Groups API.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-22 20:29:11 +00:00
Claude
2ea3936b5c Add comprehensive tests for Users API (70 tests total)
Tests include:
- User model validation (22 tests)
  - UserGroup, User, UserCreate, UserUpdate models
  - Field validation, email validation, password strength
  - CamelCase alias support

- Sync UsersEndpoint (24 tests)
  - List, get, create, update, delete operations
  - Search functionality
  - Pagination and filtering
  - Error handling and validation
  - Data normalization

- Async AsyncUsersEndpoint (24 tests)
  - Complete async coverage matching sync API
  - All CRUD operations tested
  - Validation and error handling

All 70 tests passing. Achieves >95% coverage for Users API code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-22 20:18:27 +00:00
19362ddeb3 testing adjustments 2025-07-30 21:34:55 -04:00
ade9aacf56 Fix code formatting and linting issues
- Updated GitHub Actions workflow to use correct flake8 configuration
- Fixed line length issues by using 88 characters as configured
- Removed unused imports and trailing whitespace
- Fixed f-string placeholders and unused variables
- All linting checks now pass with project configuration

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-30 20:49:40 -04:00
18a82711cb ready for try 2025-07-29 20:16:11 -04:00