This commit resolves a critical N+1 performance issue in the article sync process and introduces a major refactoring to simplify authentication, improve API reliability, and enhance the developer experience.
Major Changes:
- **Perf: Eliminate N+1 API Calls in Sync**
- Reworked the /api/kobo/get handler to fetch all bookmark details in a single batch request to Readeck's /api/bookmarks/sync endpoint.
- This replaces the previous method of making an individual API call for each article, resolving a significant performance bottleneck that caused server instability under load.
- **Refactor: Simplify Authentication**
- Removed the package and all related encryption logic. The application now uses plain-text Readeck access tokens directly in the configuration, greatly simplifying setup.
- Replaced the old token generation script with a simpler Generated a new token for your device:
b25ae315-36cc-4a8c-9515-2d729c2db526
Please add this token to your 'config.yaml' file under the 'users' section.
For example:
users:
- token: "b25ae315-36cc-4a8c-9515-2d729c2db526"
readeck_access_token: "your-plain-text-readeck-access-token"
You can get your Readeck access token from your Readeck instance's settings page..
- **Fix: API and Sync Reliability**
- Corrected the Readeck API request payload for the new batch sync, fixing a bug that caused empty results.
- Implemented robust URL matching for the /download endpoint to handle variations in query parameters and prefixes.
- **Feat: Developer Experience and Testing**
- Introduced a new package for leveled logging.
- Added debug-level logging for all incoming Kobo API requests to aid troubleshooting.
- Added a suite of end-to-end shell scripts in for manual testing of all API endpoints.
- **Test: Refactor and Enhance Unit Tests**
- Refactored the application and client test suites to reflect the new single-batch API call, removing mocks for the old N+1 behavior.
- Added comprehensive unit tests for the new URL comparison logic.
- Corrected and improved mock responses and assertions across the test suite to align with the updated API payloads and application behavior.
- **Docs: Improve Clarity and Accuracy**
- Rewrote the API Endpoints section in for clarity.
- Updated documentation to reflect the new authentication model and E2E tests.
68 lines
1.2 KiB
Go
68 lines
1.2 KiB
Go
package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"strings"
|
|
)
|
|
|
|
type Level int
|
|
|
|
const (
|
|
ERROR Level = iota
|
|
WARN
|
|
INFO
|
|
DEBUG
|
|
)
|
|
|
|
func ParseLevel(lvl string) (Level, error) {
|
|
switch strings.ToLower(lvl) {
|
|
case "error":
|
|
return ERROR, nil
|
|
case "warn":
|
|
return WARN, nil
|
|
case "info":
|
|
return INFO, nil
|
|
case "debug":
|
|
return DEBUG, nil
|
|
}
|
|
return INFO, fmt.Errorf("invalid log level: %s", lvl)
|
|
}
|
|
|
|
// Logger is a simple leveled logger.
|
|
type Logger struct {
|
|
level Level
|
|
}
|
|
|
|
// New creates a new Logger.
|
|
func New(level Level) *Logger {
|
|
return &Logger{level: level}
|
|
}
|
|
|
|
// Errorf prints a formatted error message.
|
|
func (l *Logger) Errorf(format string, v ...interface{}) {
|
|
if l.level >= ERROR {
|
|
log.Printf(format, v...)
|
|
}
|
|
}
|
|
|
|
// Warnf prints a formatted warning message.
|
|
func (l *Logger) Warnf(format string, v ...interface{}) {
|
|
if l.level >= WARN {
|
|
log.Printf(format, v...)
|
|
}
|
|
}
|
|
|
|
// Infof prints a formatted info message.
|
|
func (l *Logger) Infof(format string, v ...interface{}) {
|
|
if l.level >= INFO {
|
|
log.Printf(format, v...)
|
|
}
|
|
}
|
|
|
|
// Debugf prints a formatted debug message.
|
|
func (l *Logger) Debugf(format string, v ...interface{}) {
|
|
if l.level >= DEBUG {
|
|
log.Printf(format, v...)
|
|
}
|
|
} |