Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
This commit is contained in:
1 parent
288e6e94ac
commit
c1175d389f
699 files changed
+110197
-4117
No files matched your search
@@ -1,15 +1,29 @@
|
||||
package store
|
||||
|
||||
import "os"
|
||||
|
||||
type RecentObject struct {
|
||||
UUID string
|
||||
Path string
|
||||
Size int
|
||||
UpdatedAt int64
|
||||
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
|
||||
@@ -18,12 +32,15 @@ func (s *Store) ListRecentObjects(
|
||||
rows, err := s.DB.Query(`
|
||||
WITH latest AS (
|
||||
SELECT
|
||||
r.uuid,
|
||||
r.object_uuid,
|
||||
r.body,
|
||||
COALESCE(r.document_hash, '') AS document_hash,
|
||||
r.created_at,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY r.object_uuid
|
||||
ORDER BY r.created_at DESC
|
||||
ORDER BY
|
||||
COALESCE(r.created_at_ms, r.created_at * 1000) DESC,
|
||||
r.rowid DESC
|
||||
) AS rn
|
||||
FROM revisions r
|
||||
),
|
||||
@@ -38,30 +55,35 @@ func (s *Store) ListRecentObjects(
|
||||
p.path ASC
|
||||
) AS rn
|
||||
FROM paths p
|
||||
WHERE p.domain_uuid = ?
|
||||
)
|
||||
SELECT
|
||||
o.uuid,
|
||||
COALESCE(ranked_path.path, ''),
|
||||
COALESCE(LENGTH(latest.body), 0),
|
||||
COALESCE(latest.created_at, o.created_at)
|
||||
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 ranked_path
|
||||
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 ?
|
||||
`, limit)
|
||||
`, domainUUID, limit)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
|
||||
var out []RecentObject
|
||||
|
||||
for rows.Next() {
|
||||
@@ -73,6 +95,7 @@ func (s *Store) ListRecentObjects(
|
||||
&ro.Path,
|
||||
&ro.Size,
|
||||
&ro.UpdatedAt,
|
||||
&ro.documentHash,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
@@ -81,6 +104,24 @@ func (s *Store) ListRecentObjects(
|
||||
|
||||
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 path, err := s.documentPath(out[i].documentHash); err == nil && path != "" {
|
||||
if info, err := os.Stat(path); err == nil {
|
||||
out[i].Size = int(info.Size())
|
||||
}
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
Reference in new issue
Block a user