mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-12 08:27:27 +02:00
19cf50027d2b49e3e15ce3f2d68cc6991d90a81c
This commit replaces the batched relay connection approach with a much
cleaner LIMIT-based strategy that requests recent messages first, then
backfills history after AUTH completes.
## Why This Approach is Better
**Previous Approach (Batched Connections)**:
- Connected to relays in batches (3, then 2, then 2...)
- Complex batching logic with timeouts
- Artificial delays between relay connections
- Still requested ALL messages from each batch immediately
**New Approach (LIMIT-based Loading)**:
- Connect to ALL relays normally at once
- Request only 20 most recent messages initially (with LIMIT)
- After 3s delay (allowing AUTH), backfill full history
- Much simpler code, better performance
## How It Works
### Step 1: Initial REQ with LIMIT (T+0s)
```typescript
REQ ["sub_id", {"kinds": [1059], "#p": ["user"], "limit": 20}]
```
- Connects to all relays
- Requests only 20 most recent gift wraps
- Fast response, minimal processing
- AUTH happens naturally with relays
- Messages appear within seconds
### Step 2: Backfill REQ (T+3s)
```typescript
REQ ["sub_id", {"kinds": [1059], "#p": ["user"]}]
```
- AUTH is complete by now
- Requests full history (no limit)
- Smooth progressive loading
- Browser stays responsive
## Benefits
**Simplicity**:
- ✅ No complex batching logic
- ✅ No artificial connection delays
- ✅ Straightforward 2-step process
- ✅ 60 fewer lines of code
**Performance**:
- ✅ All relays connect immediately
- ✅ Recent messages appear fast (LIMIT)
- ✅ Browser not overwhelmed by processing
- ✅ AUTH completes before backfill
- ✅ Smooth user experience
**Network**:
- ✅ Fewer total REQs (2 vs many batches)
- ✅ Better relay coverage from start
- ✅ No redundant subscriptions
## Configuration
```typescript
const INITIAL_LIMIT = 20; // Recent messages first
const BACKFILL_DELAY_MS = 3000; // 3s delay for AUTH
```
## Testing
- ✅ All 864 tests pass
- ✅ Build succeeds with no errors
- ✅ Verified 2-step loading flow
- ✅ Confirmed browser responsiveness
## Files Changed
- `src/services/gift-wrap.ts` - Replaced batching with LIMIT approach
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…
Grimoire
A Nostr protocol explorer and developer tool with a tiling window manager interface.
Features
- Tiling Windows - Each window is a Nostr "app" (profile viewer, event feed, NIP docs, etc.)
- Command Palette - Unix-style commands via
Cmd+Kto open apps and navigate - Multi-workspace - Virtual desktops with independent layouts
- Real-time - Reactive event subscriptions with automatic updates
Stack
React 19, TypeScript, Vite, TailwindCSS, Jotai, Dexie, Applesauce
Getting Started
npm install
npm run dev
Scripts
| Command | Description |
|---|---|
npm run dev |
Start dev server |
npm run build |
Build for production |
npm test |
Run tests in watch mode |
npm run lint |
Lint code |
npm run format |
Format code |
License
MIT
Languages
TypeScript
98.9%
CSS
0.8%
JavaScript
0.3%