feat: SQLite event storage with pagination and filtering
Implement SQLite-based event persistence as specified in sqlite-event-manager.md.
## Changes
### Backend
- **EventStorage** (`src/classes/event_storage.py`): New SQLite storage layer
- Cursor-based pagination with compound cursor `{month_stamp}_{rowid}`
- Avatar filtering (single and pair queries)
- Major/minor event separation
- Cleanup API with `keep_major` and `before_month_stamp` filters
- **EventManager** (`src/classes/event_manager.py`): Refactored to use SQLite
- Delegates to EventStorage for persistence
- Memory fallback mode for testing
- New `get_events_paginated()` method
- **API** (`src/server/main.py`):
- `GET /api/events` - Paginated event retrieval with filtering
- `DELETE /api/events/cleanup` - User-triggered cleanup
### Frontend
- **EventPanel.vue**: Scroll-to-load pagination, dual-person filter UI
- **world.ts**: Event state management with pagination
- **game.ts**: New API client methods
### Testing
- 81 new tests for EventStorage, EventManager, and API
- Added `pytest-asyncio` and `httpx` to requirements.txt
## Known Issues: Save/Load is Currently Broken
After loading a saved game, the following issues occur:
1. **Wrong database used**: API returns events from the startup database instead
of the loaded save's `_events.db` file
2. **Events from wrong time period**: Shows events from year 115 when loaded
save is at year 114
3. **Pagination broken after load**: `has_more` returns `False` despite hundreds
of events in the saved database
4. **Filter functionality broken**: Character selection filter stops working
after loading a game
Root cause: `load_game.py` does not properly switch the EventManager's database
connection to the loaded save's events database.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from src.classes.map import Map
|
||||
@@ -63,4 +64,29 @@ class World():
|
||||
"动作": "你有一系列可以执行的动作。要注意动作的效果、限制条件、区域和时间。",
|
||||
"装备与丹药": "通过兵器、辅助装备、丹药等装备,可以获得额外的属性加成,获得或小或大的增益。拥有好的装备或者服用好的丹药,能获得很大好处。",
|
||||
}
|
||||
return desc
|
||||
return desc
|
||||
|
||||
@classmethod
|
||||
def create_with_db(
|
||||
cls,
|
||||
map: "Map",
|
||||
month_stamp: MonthStamp,
|
||||
events_db_path: Path,
|
||||
) -> "World":
|
||||
"""
|
||||
工厂方法:创建使用 SQLite 持久化事件的 World 实例。
|
||||
|
||||
Args:
|
||||
map: 地图对象。
|
||||
month_stamp: 时间戳。
|
||||
events_db_path: 事件数据库文件路径。
|
||||
|
||||
Returns:
|
||||
配置好的 World 实例。
|
||||
"""
|
||||
event_manager = EventManager.create_with_db(events_db_path)
|
||||
return cls(
|
||||
map=map,
|
||||
month_stamp=month_stamp,
|
||||
event_manager=event_manager,
|
||||
)
|
||||
Reference in New Issue
Block a user