Deretard the cache
This commit is contained in:
27
db.go
27
db.go
@@ -28,10 +28,9 @@ type QueryParams struct {
|
||||
// CacheEntry stores both statistics (JSON) and images (blobs) in unified cache
|
||||
// For 404s, we store a special marker: []byte{0xFF, 0xFE, 0xFD} (NOT_FOUND_MARKER)
|
||||
type CacheEntry struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||||
CacheKey string `gorm:"column:cache_key;not null"`
|
||||
Data []byte `gorm:"column:data;type:BLOB;not null"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;not null"`
|
||||
CacheKey string `gorm:"primaryKey"`
|
||||
Data []byte `gorm:"type:BLOB;not null"`
|
||||
CreatedAt time.Time `gorm:"not null"`
|
||||
}
|
||||
|
||||
var notFoundMarker = []byte{0xFF, 0xFE, 0xFD} // Special marker for cached 404s
|
||||
@@ -87,18 +86,16 @@ func GetDB() (DB, error) {
|
||||
return db, nil
|
||||
}
|
||||
|
||||
// ClickHouse connection - use HTTP interface on port 8123
|
||||
// Change "localhost" to your Linux host IP or hostname
|
||||
options := &clickhouse.Options{
|
||||
Addr: []string{"clickhouse.site.quack-lab.dev"}, // TODO: Change to your Linux host, e.g., "192.168.1.100:8123" or "clickhouse.example.com:8123"
|
||||
Addr: []string{"clickhouse.site.quack-lab.dev"},
|
||||
Auth: clickhouse.Auth{
|
||||
Database: "zkill",
|
||||
Username: "default",
|
||||
Password: "", // Set if you configure a password on Linux host
|
||||
Password: "",
|
||||
},
|
||||
Protocol: clickhouse.HTTP,
|
||||
Settings: clickhouse.Settings{
|
||||
"max_query_size": 100000000, // allow larger queries when filters generate big IN (...) lists
|
||||
"max_query_size": 100000000,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -131,15 +128,9 @@ func (db *DBWrapper) InitTables() error {
|
||||
// Migrate unified cache table
|
||||
// Use raw SQL to create table and index with IF NOT EXISTS to avoid errors
|
||||
// For 404s, we store a special marker byte sequence instead of NULL
|
||||
if err := db.gormDB.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS cache_entries (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
cache_key TEXT NOT NULL,
|
||||
data BLOB NOT NULL,
|
||||
created_at DATETIME NOT NULL
|
||||
)
|
||||
`).Error; err != nil {
|
||||
return fmt.Errorf("failed to create cache_entries table: %w", err)
|
||||
err := db.gormDB.AutoMigrate(&CacheEntry{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to migrate cache_entries table: %w", err)
|
||||
}
|
||||
|
||||
// Create index if it doesn't exist
|
||||
|
||||
Reference in New Issue
Block a user