Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sort when syncing by parent #973

Merged
merged 6 commits into from
Feb 15, 2024
Merged

Conversation

kellyjosephprice
Copy link
Contributor

@kellyjosephprice kellyjosephprice commented Feb 7, 2024

🚥 Resolves RM-8336

🧰 Changes

When syncing docs, it sorts them by their parents!

Users reported issues where if a parent document was in a directory, it could error out because it would get synced after one of its children.

🧬 QA & Testing

Not sure 😬.

@kellyjosephprice kellyjosephprice changed the base branch from next to tests/mock-git-cmds February 7, 2024 21:19
@kellyjosephprice kellyjosephprice changed the title feat/sort sync heirarchy feat: sort when syncing by parent Feb 7, 2024
@kellyjosephprice kellyjosephprice requested review from erunion and kanadgupta and removed request for erunion February 7, 2024 21:26
@kellyjosephprice kellyjosephprice marked this pull request as ready for review February 7, 2024 21:27
Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow this is a very sophisticated approach, love it! i have some feedback + questions below, happy to pair on any of this!

src/lib/syncDocsPath.ts Outdated Show resolved Hide resolved
src/lib/syncDocsPath.ts Outdated Show resolved Hide resolved
Comment on lines 138 to 142
const doc = frontMatter(fsSync.readFileSync(filePath, 'utf8'));
const slug = path.basename(filePath).replace(extensionRegexp, '');
const parentDocSlug = doc.data.parentDocSlug;

return { filePath, slug, parentDocSlug };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a readDoc utility that should take care of this, mind using that instead? also it appears we're reading each file twice now, any way we could optimize that1?

Footnotes

  1. just flagging it so we're aware, but i don't think it's a real issue!


const dependencies = Object.values(filesBySlug).reduce(
(edges, obj) => {
if (obj.parentDocSlug) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know we have users that sync only parts of their docs using rdme, i think we should probably also ensure that the parent file actually exists

(also let me know if i'm misunderstanding how this works!)

Suggested change
if (obj.parentDocSlug) {
if (obj.parentDocSlug && filesBySlug[obj.parentDocSlug]) {

@@ -127,6 +130,40 @@ async function pushDoc(
});
}

function sortFiles(files: string[], { allowedFileExtensions }: { allowedFileExtensions: string[] }): string[] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function appears to use parentDocSlug, is there any way we add basic support for parentDoc? i know it uses object IDs so there's no way for us to build a graph, but at the very least we could make it so docs that have a parentDoc attribute get synced after ones that lack one?

Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Comment on lines -33 to +36
const { content, data, hash, slug } = readDoc(filePath);
const { content, data, filePath, hash, slug } = fileData;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this refactor (i.e., decoupling the readDoc so we can read the contents prior to sorting) is very clever!

Base automatically changed from tests/mock-git-cmds to next February 15, 2024 00:38
@kellyjosephprice kellyjosephprice merged commit 9795840 into next Feb 15, 2024
8 checks passed
@kellyjosephprice kellyjosephprice deleted the feat/sort-sync-heirarchy branch February 15, 2024 00:56
kanadgupta pushed a commit that referenced this pull request Feb 15, 2024
# [9.0.0-next.11](v9.0.0-next.10...v9.0.0-next.11) (2024-02-15)

### Features

* sort when syncing by parent ([#973](#973)) ([9795840](9795840))

[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants