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.
126 lines
2.3 KiB
Go
126 lines
2.3 KiB
Go
package store
|
|
|
|
type RecentObject struct {
|
|
UUID string
|
|
Path string
|
|
Size int
|
|
UpdatedAt int64
|
|
documentHash string
|
|
}
|
|
|
|
func (s *Store) ListRecentObjects(
|
|
limit int,
|
|
) ([]RecentObject, error) {
|
|
domainUUID, err := s.defaultDomainUUID()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return s.ListRecentObjectsInDomain(domainUUID, limit)
|
|
}
|
|
|
|
func (s *Store) ListRecentObjectsInDomain(
|
|
domainUUID string,
|
|
limit int,
|
|
) ([]RecentObject, error) {
|
|
|
|
if limit <= 0 {
|
|
limit = 20
|
|
}
|
|
|
|
rows, err := s.DB.Query(`
|
|
WITH latest AS (
|
|
SELECT
|
|
r.uuid,
|
|
r.object_uuid,
|
|
COALESCE(r.document_hash, '') AS document_hash,
|
|
r.created_at,
|
|
ROW_NUMBER() OVER (
|
|
PARTITION BY r.object_uuid
|
|
ORDER BY
|
|
COALESCE(r.created_at_ms, r.created_at * 1000) DESC,
|
|
r.rowid DESC
|
|
) AS rn
|
|
FROM revisions r
|
|
),
|
|
ranked_path AS (
|
|
SELECT
|
|
p.object_uuid,
|
|
p.path,
|
|
ROW_NUMBER() OVER (
|
|
PARTITION BY p.object_uuid
|
|
ORDER BY
|
|
COALESCE(p.is_primary, 0) DESC,
|
|
p.path ASC
|
|
) AS rn
|
|
FROM paths p
|
|
WHERE p.domain_uuid = ?
|
|
)
|
|
SELECT
|
|
o.uuid,
|
|
COALESCE(ranked_path.path, ''),
|
|
CASE
|
|
WHEN latest.document_hash <> '' THEN 0
|
|
ELSE COALESCE(LENGTH(r.body), 0)
|
|
END,
|
|
COALESCE(latest.created_at, o.created_at),
|
|
COALESCE(latest.document_hash, '')
|
|
FROM objects o
|
|
LEFT JOIN latest
|
|
ON latest.object_uuid = o.uuid
|
|
AND latest.rn = 1
|
|
LEFT JOIN revisions r
|
|
ON r.uuid = latest.uuid
|
|
JOIN ranked_path
|
|
ON ranked_path.object_uuid = o.uuid
|
|
AND ranked_path.rn = 1
|
|
ORDER BY
|
|
COALESCE(latest.created_at, o.created_at) DESC
|
|
LIMIT ?
|
|
`, domainUUID, limit)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out []RecentObject
|
|
|
|
for rows.Next() {
|
|
|
|
var ro RecentObject
|
|
|
|
err := rows.Scan(
|
|
&ro.UUID,
|
|
&ro.Path,
|
|
&ro.Size,
|
|
&ro.UpdatedAt,
|
|
&ro.documentHash,
|
|
)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out = append(out, ro)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
for i := range out {
|
|
if out[i].Size != 0 {
|
|
continue
|
|
}
|
|
if out[i].documentHash == "" {
|
|
continue
|
|
}
|
|
if s.DocumentRoot != "" {
|
|
if size, err := s.DocumentSize(out[i].documentHash); err == nil {
|
|
out[i].Size = int(size)
|
|
}
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|