feat(storage): add native PostgreSQL runtime and verified offline application import
Build and publish container images / images (push) Failing after 12m29s
Build and publish container images / images (push) Failing after 12m29s
This commit is contained in:
1 parent
96065d1e89
commit
0ba1dcfef0
243 files changed
+21441
-3090
No files matched your search
+61
-14
@@ -1,11 +1,37 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"pageswiki/internal/mestionora"
|
||||
)
|
||||
|
||||
func (s *Store) fillNativeBrowserTitles(entries []BrowserEntry) error {
|
||||
if s.sqlBackend != storePostgreSQL {
|
||||
return nil
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), cityReadTimeout)
|
||||
defer cancel()
|
||||
budget := int64(32 << 20)
|
||||
for i := range entries {
|
||||
e := &entries[i]
|
||||
if e.IsDir || e.DocumentHash == "" || !strings.HasPrefix(strings.ToLower(e.ContentType), "text/html") {
|
||||
continue
|
||||
}
|
||||
if budget < 65536 {
|
||||
return ErrNavigationBudget
|
||||
}
|
||||
window, err := s.ReadDocumentWindowContext(ctx, e.DocumentHash, 0, 65536)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
budget -= int64(len(window.Data))
|
||||
e.Title = firstHTMLHeading(string(window.Data))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type BrowserEntry struct {
|
||||
Name string
|
||||
Path string
|
||||
@@ -46,34 +72,43 @@ func (s *Store) ListBrowserEntries(parent string) ([]BrowserEntry, error) {
|
||||
}
|
||||
|
||||
func (s *Store) ListBrowserEntriesInDomain(domainUUID, parent string) ([]BrowserEntry, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), cityReadTimeout)
|
||||
defer cancel()
|
||||
parent = normalizeBrowserPath(parent)
|
||||
prefix := strings.TrimRight(parent, "/") + "/"
|
||||
// Collapse descendants before consulting revisions. A folder listing must
|
||||
// not rank every revision of every document in the subtree. Binary ranges
|
||||
// keep prefix matching literal (including %, _) and use the Path index.
|
||||
rows, err := s.DB.Query(`
|
||||
pos := s.sqlStringPosition("name", "/")
|
||||
byteSize := "length(CAST(r.body AS BLOB))"
|
||||
tie := "rowid"
|
||||
if s.sqlBackend == storePostgreSQL {
|
||||
byteSize = "octet_length(r.body)"
|
||||
tie = "uuid"
|
||||
}
|
||||
rows, err := s.DB.QueryContext(ctx, `
|
||||
WITH relative AS (
|
||||
SELECT substr(path, length(?) + 1) AS name, object_uuid
|
||||
FROM paths WHERE domain_uuid=? AND path >= ? AND path < ? AND path != ?
|
||||
SELECT substr(path, length(`+s.sqlParam(1)+`) + 1) AS name, object_uuid
|
||||
FROM paths WHERE domain_uuid=`+s.sqlParam(2)+` AND path >= `+s.sqlParam(3)+` AND path < `+s.sqlParam(4)+` AND path != `+s.sqlParam(5)+`
|
||||
), children AS (
|
||||
SELECT CASE WHEN instr(name,'/')=0 THEN name ELSE substr(name,1,instr(name,'/')-1) END AS name,
|
||||
MAX(CASE WHEN instr(name,'/')=0 THEN object_uuid ELSE '' END) AS object_uuid,
|
||||
MAX(instr(name,'/')>0) AS is_dir,
|
||||
SUM(instr(name,'/')>0) AS child_count
|
||||
SELECT CASE WHEN `+pos+`=0 THEN name ELSE substr(name,1,`+pos+`-1) END AS name,
|
||||
MAX(CASE WHEN `+pos+`=0 THEN object_uuid ELSE '' END) AS object_uuid,
|
||||
MAX(CASE WHEN `+pos+`>0 THEN 1 ELSE 0 END) AS is_dir,
|
||||
SUM(CASE WHEN `+pos+`>0 THEN 1 ELSE 0 END) AS child_count
|
||||
FROM relative WHERE name != '' GROUP BY 1
|
||||
)
|
||||
SELECT c.name,c.object_uuid,c.is_dir,c.child_count,
|
||||
COALESCE(length(CAST(r.body AS BLOB)),0),COALESCE(r.created_at,0),
|
||||
COALESCE(`+byteSize+`,0),COALESCE(r.created_at,0),
|
||||
COALESCE(r.content_type,''),COALESCE(r.filename,''),
|
||||
COALESCE(r.document_hash,''),COALESCE(r.uuid,''),
|
||||
COALESCE(substr(CAST(r.body AS TEXT),1,65536),'')
|
||||
FROM children c LEFT JOIN revisions r ON r.rowid=(
|
||||
SELECT head.rowid FROM revisions head
|
||||
FROM children c LEFT JOIN revisions r ON r.`+tie+`=(
|
||||
SELECT head.`+tie+` FROM revisions head
|
||||
WHERE c.is_dir=0 AND head.object_uuid=c.object_uuid
|
||||
ORDER BY head.created_at_ms DESC, head.rowid DESC LIMIT 1
|
||||
ORDER BY head.created_at_ms DESC, head.`+tie+` DESC LIMIT 1
|
||||
)
|
||||
ORDER BY c.is_dir DESC,c.name ASC
|
||||
`, prefix, domainUUID, prefix, strings.TrimSuffix(prefix, "/")+"0", parent)
|
||||
ORDER BY c.is_dir DESC,c.name ASC LIMIT `+s.sqlParam(6)+`
|
||||
`, prefix, domainUUID, prefix, strings.TrimSuffix(prefix, "/")+"0", parent, MaxNavigationEntries+1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -95,6 +130,18 @@ func (s *Store) ListBrowserEntriesInDomain(domainUUID, parent string) ([]Browser
|
||||
}
|
||||
}
|
||||
out = append(out, entry)
|
||||
if len(out) > MaxNavigationEntries {
|
||||
return nil, ErrNavigationBudget
|
||||
}
|
||||
}
|
||||
return out, rows.Err()
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.fillNativeBrowserTitles(out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
Reference in new issue
Block a user