Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
This commit is contained in:
1 parent
9dd425f765
commit
d5d21b7841
302 files changed
+20037
-3492
No files matched your search
@@ -1,9 +1,9 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
const MaxDocumentWindowBytes int64 = 256 << 10
|
||||
@@ -17,6 +17,13 @@ type DocumentWindow struct {
|
||||
}
|
||||
|
||||
func (s *Store) ReadDocumentWindow(documentHash string, offset, limit int64) (DocumentWindow, error) {
|
||||
return s.ReadDocumentWindowContext(context.Background(), documentHash, offset, limit)
|
||||
}
|
||||
|
||||
func (s *Store) ReadDocumentWindowContext(ctx context.Context, documentHash string, offset, limit int64) (DocumentWindow, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return DocumentWindow{}, err
|
||||
}
|
||||
if offset < 0 {
|
||||
return DocumentWindow{}, errors.New("negative Document offset")
|
||||
}
|
||||
@@ -27,32 +34,32 @@ func (s *Store) ReadDocumentWindow(documentHash string, offset, limit int64) (Do
|
||||
limit = MaxDocumentWindowBytes
|
||||
}
|
||||
if s.DocumentRoot != "" {
|
||||
path, err := s.DocumentPath(documentHash)
|
||||
backend, err := s.documentStorage()
|
||||
if err != nil {
|
||||
return DocumentWindow{}, err
|
||||
}
|
||||
file, err := os.Open(path)
|
||||
file, err := backend.Open(ctx, documentHash)
|
||||
if err != nil {
|
||||
return DocumentWindow{}, err
|
||||
}
|
||||
defer file.Close()
|
||||
info, err := file.Stat()
|
||||
size, err := file.Seek(0, io.SeekEnd)
|
||||
if err != nil {
|
||||
return DocumentWindow{}, err
|
||||
}
|
||||
if offset > info.Size() {
|
||||
offset = info.Size()
|
||||
if offset > size {
|
||||
offset = size
|
||||
}
|
||||
data := make([]byte, minInt64(limit, info.Size()-offset))
|
||||
data := make([]byte, minInt64(limit, size-offset))
|
||||
n, err := file.ReadAt(data, offset)
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
return DocumentWindow{}, err
|
||||
}
|
||||
data = data[:n]
|
||||
return DocumentWindow{Data: data, Offset: offset, NextOffset: offset + int64(n), TotalBytes: info.Size(), Truncated: offset+int64(n) < info.Size()}, nil
|
||||
return DocumentWindow{Data: data, Offset: offset, NextOffset: offset + int64(n), TotalBytes: size, Truncated: offset+int64(n) < size}, nil
|
||||
}
|
||||
var body string
|
||||
if err := s.DB.QueryRow(`SELECT COALESCE(body,'') FROM revisions WHERE document_hash=? ORDER BY rowid DESC LIMIT 1`, documentHash).Scan(&body); err != nil {
|
||||
if err := s.DB.QueryRowContext(ctx, `SELECT COALESCE(body,'') FROM revisions WHERE document_hash=? ORDER BY rowid DESC LIMIT 1`, documentHash).Scan(&body); err != nil {
|
||||
return DocumentWindow{}, err
|
||||
}
|
||||
total := int64(len(body))
|
||||
@@ -79,18 +86,25 @@ func (s *Store) GetRevisionMetadata(revisionUUID string) (*Revision, error) {
|
||||
}
|
||||
|
||||
func (s *Store) DocumentSize(documentHash string) (int64, error) {
|
||||
return s.DocumentSizeContext(context.Background(), documentHash)
|
||||
}
|
||||
|
||||
func (s *Store) DocumentSizeContext(ctx context.Context, documentHash string) (int64, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if s.DocumentRoot != "" {
|
||||
path, err := s.DocumentPath(documentHash)
|
||||
backend, err := s.documentStorage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
info, err := os.Stat(path)
|
||||
info, err := backend.Stat(ctx, documentHash)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return info.Size(), nil
|
||||
return info.Size, nil
|
||||
}
|
||||
var size int64
|
||||
err := s.DB.QueryRow(`SELECT length(COALESCE(body,'')) FROM revisions WHERE document_hash=? ORDER BY rowid DESC LIMIT 1`, documentHash).Scan(&size)
|
||||
err := s.DB.QueryRowContext(ctx, `SELECT length(CAST(COALESCE(body,'') AS BLOB)) FROM revisions WHERE document_hash=? ORDER BY rowid DESC LIMIT 1`, documentHash).Scan(&size)
|
||||
return size, err
|
||||
}
|
||||
Reference in new issue
Block a user