Remove SQLite: use in-memory cache instead

This commit is contained in:
lyn
2026-04-14 13:04:24 +00:00
parent 1e853e9f75
commit 0a2ec1d048

View File

@@ -30,11 +30,11 @@ A lightweight Go service that:
## Tech Stack ## Tech Stack
- **Language**: Go - **Language**: Go
- **Database**: SQLite (local cache)
- **Source DB**: Gitea MySQL (read-only, same docker network) - **Source DB**: Gitea MySQL (read-only, same docker network)
- **HTTP**: Standard library `net/http` - **HTTP**: Standard library `net/http`
- **Deployment**: Docker + Docker Compose on vps.git - **Deployment**: Docker + Docker Compose on vps.git
- **API Key**: Rotates every 10 minutes, stored in Docker volume at `/data/api-key` - **API Key**: Rotates every 10 minutes, stored in Docker volume at `/data/api-key`
- **Cache**: In-memory map (repo_id → Repo), refreshed every 5h + webhook updates
## Authentication ## Authentication
@@ -97,16 +97,20 @@ Returns `{"status": "ok"}`.
## Data Model ## Data Model
### SQLite cache table: `repos` ### In-memory cache: `map[int64]*Repo`
| Column | Type | Notes | ```go
|--------------|---------|------------------------------| type Repo struct {
| id | INTEGER | Gitea repo ID (primary key) | ID int64
| name | TEXT | | Name string
| owner | TEXT | Gitea username of owner | Owner string
| is_private | INTEGER | 0 or 1 | IsPrivate bool
| url | TEXT | Full .git HTTPS URL | URL string
| updated_at | INTEGER | Unix timestamp of last sync | }
```
Cached in a `sync.RWMutex`-protected map keyed by Gitea repo ID.
Refreshed on startup, every 5 hours, and on webhook events.
## Configuration ## Configuration
@@ -118,8 +122,6 @@ Environment variables:
| `DB_USER` | `root` | MySQL username | | `DB_USER` | `root` | MySQL username |
| `DB_PASS` | — | MySQL password | | `DB_PASS` | — | MySQL password |
| `DB_NAME` | `giteadb` | MySQL database name | | `DB_NAME` | `giteadb` | MySQL database name |
| `SQLITE_PATH` | `/data/cache.db` | SQLite file path |
| `API_KEY_FILE` | `/data/api-key` | Path for rotating api-key |
| `WEBHOOK_SECRET` | — | Gitea webhook secret token | | `WEBHOOK_SECRET` | — | Gitea webhook secret token |
| `PORT` | `8080` | HTTP listen port | | `PORT` | `8080` | HTTP listen port |
@@ -150,11 +152,9 @@ services:
DB_USER: root DB_USER: root
DB_PASS: ${MYSQL_ROOT_PASSWORD} DB_PASS: ${MYSQL_ROOT_PASSWORD}
DB_NAME: giteadb DB_NAME: giteadb
SQLITE_PATH: /data/cache.db
WEBHOOK_SECRET: ${GITEA_WEBHOOK_SECRET} WEBHOOK_SECRET: ${GITEA_WEBHOOK_SECRET}
PORT: 8080 PORT: 8080
volumes: volumes:
- ./gitea-custom-api/data:/data
- ./gitea-custom-api/api-key:/data/api-key - ./gitea-custom-api/api-key:/data/api-key
networks: networks:
- git-network - git-network