orama-db: `orama-db.json` changes on every build
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, node.js
Hướng nghiên cứu
Start with packages/react/src/orama-db/generate.mjs: read how it builds documents, calls insertMultiple, and saves the index; the issue also points to useOrama.mjs to check how search uses results. Add stable ids and sort the flattened documents by href, then create the suggested generator tests for repeatability, input order, and search behavior. Run node --run test and confirm the generated output is stable; pull request #1190 is already open against this issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Running a build twice on the same docs gives two different orama-db.json files, for two reasons:
- Timestamp-based ids. The
orama-dbgenerator inserts documents without anid, so Orama 3.x makes one up from the current time and a counter (e.g.20003290-1). That id is saved in the index (internalDocumentIDStore.internalIdToId), so the file changes on every build. - Insertion order. Orama's saved index follows the order documents were inserted, and the generator's input order can change between builds (see #1183).
The search index is several MB, so a file that changes on every deploy wastes caching, and CI can't compare it byte for byte.
Where to look
packages/react/src/orama-db/generate.mjs:27-44: builds the documents (title,description,href,siteSection) with noid, in input order.- The same file, line 40:
href(${entry.path}.html#${entry.heading.data.slug}), which makes a natural stable id. - The same file, line 47:
insertMultiple(db, documents); lines 49-56:save(db)is written toorama-db.json. packages/react/src/html/ui/hooks/useOrama.mjs:26-41: the website loads the saved index and searches it. It doesn't depend on the id format, and results are rendered fromhit.document.
How to reproduce
From packages/react (where @orama/orama resolves), save this as repro.mjs and run node repro.mjs a few times:
import { createHash } from 'node:crypto';
import { create, insertMultiple, save } from '@orama/orama';
const docs = [
{ title: 'fs', description: 'File system', href: 'fs.html#fs', siteSection: 'fs' },
{ title: 'fs > readFile', description: 'Reads a file', href: 'fs.html#readfile', siteSection: 'fs' },
];
const db = create({
schema: { title: 'string', description: 'string', href: 'string', siteSection: 'string' },
});
await insertMultiple(db, docs); // try: docs.map(doc => ({ id: doc.href, ...doc }))
const out = JSON.stringify(save(db));
console.log(createHash('sha256').update(out).digest('hex').slice(0, 16));
Each run prints a different hash. With the commented id: doc.href line, every run prints the same one, until you reverse docs, which changes it again.
Suggested approach
Only packages/react/src/orama-db/generate.mjs needs to change:
- Add
id: hrefto each document (Orama requires string ids, andhrefis one). - Sort the flattened documents by
hrefbefore inserting them, comparing with<and>(orlocaleCompare(..., 'en')) so the order doesn't depend on the machine's locale.
Keep the existing flatMap as it is, and sort its result, not the input: buildHierarchicalTitle walks each module's headings in document order to build titles like "Class > Method".
How to test
There's no generator test for orama-db yet. Create packages/react/src/orama-db/__tests__/generate.test.mjs, setting up the config like llms-txt-full/__tests__/generate.test.mjs does (setConfig({ target: ['orama-db'] }), then set output to undefined so generate() just returns the saved index). With a few fake metadata entries from two modules, test that:
- Two runs give the same output: compare the
JSON.stringifyof twogenerate()results. This already fails today within a single process. - Input order doesn't matter: put one module's entries before the other's, keeping each module's own entries in order, and compare.
- Search still works:
load()the result intocreate({ schema: {} }),search()for a title word, and checkhits[0].document.href.
Run everything with node --run test.
Things to watch out for
- Ids must be unique, or Orama throws
DOCUMENT_ALREADY_EXISTSand the build fails. Slugs are deduplicated per file, so hrefs should be unique. If the full Node.js docs build throws anyway, point out the duplicate in your PR rather than going back to automatic ids. save()doesn't include the database's own id, so that one doesn't matter.- The output is only identical for the same
@orama/oramaversion; a dependency update can still change it.
Getting started
New to doc-kit? CONTRIBUTING.md covers setup, running the tests and adding a changeset (node --run changeset, a patch for @doc-kit/generator-react). Leave a comment here if you'd like to take it on.
- Ngôn ngữ chính
- JavaScript
- Star
- 70
- Fork
- 75
- Merge trung bình
- 2 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 50
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nodejs/doc-kit
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 68/100
nodejs/doc-kit#1085 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
nodejs/doc-kit#1054 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
nodejs/doc-kit#1194 · 1 reaction ·
Maintainer thường phản hồi trong vòng 3 ngày
-
core: incremental generation against an existing output (`--incremental`)Có thể đã có người làm @avivkeller đã nhận 2 ngày trước. Đang mởCLI
nodejs/doc-kit#1189 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
cli: add a `dev` command with in-memory builds and HMRCó thể đã có người làm @avivkeller đã nhận 2 ngày trước. Đang mởCLI Web Generator
nodejs/doc-kit#1188 · 1 reaction · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của nodejs/doc-kit
Issue tương tự
-
Pills' meter dots fade on bright and deep pillsCó thể đã có người làm @wassim-azi đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
wassim-azi/agy-powerline#168 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
accounts bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:docs effort:S impact:S kind:docs source:critic stage:ready
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 91/100
Jason-Vaughan/TangleClaw#2693 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
infrastructure P2 security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Energy flow: add an "Other" row so the consumers add up to the consumption totalCó thể đã có người làm @github-actions đã nhận hôm nay. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
evcc-io/evcc#35512 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày