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

BREAKING CHANGE: Refactor fs #8792

Merged
merged 70 commits into from Mar 28, 2023
Merged

BREAKING CHANGE: Refactor fs #8792

merged 70 commits into from Mar 28, 2023

Conversation

andelf
Copy link
Collaborator

@andelf andelf commented Mar 9, 2023

Warning
This PR rewrites some of the underlying fs implementation and path handling.

Requires at least 3 or more devs' approval.

@andelf andelf changed the title Refactor fs BREAKING CHANGE: Refactor fs Mar 11, 2023
@andelf andelf marked this pull request as ready for review March 11, 2023 09:48
@andelf andelf changed the title BREAKING CHANGE: Refactor fs WIP: BREAKING CHANGE: Refactor fs Mar 11, 2023
@andelf andelf added :type/question Not bug, closed at will. Frequently asked ones would be collected in Logseq Forum's FAQ section. :type/bug-fix breaking-change estimate: large Require major refactor of a feature help-wanted Need help from people with specific environment or konwledge and removed :type/question Not bug, closed at will. Frequently asked ones would be collected in Logseq Forum's FAQ section. labels Mar 11, 2023
@andelf
Copy link
Collaborator Author

andelf commented Mar 14, 2023

Now the basic refactoring is done and ready for early review.

How to Test

  • This PR is a BREAKING CHANGE, Clear Cache is required

Platform Checklist

  • Electron
  • Electron on Windows
  • Android
  • iOS
  • Demo graph (on-boarding) on all platforms
  • Browser (Chrome)

Operations

  • Open Graph
  • Refresh Graph
  • Re-index Graph
  • Basic block editing
  • File creating & deleting & renaming
  • Asset adding & deleting
  • Config editing
  • Global Config editing
  • Special page names, on macOS/Linux, Windows, Android, iOS
  • Special graph names, on macOS/Linux, Windows, Android, iOS
  • Special graph paths, on macOS/Linux, Windows, Android, iOS
  • Work with Logseq Sync

@andelf andelf changed the title WIP: BREAKING CHANGE: Refactor fs BREAKING CHANGE: Refactor fs Mar 14, 2023
@andelf andelf added this to the 0.8.19 milestone Mar 14, 2023
deps/common/src/logseq/common/path.cljs Outdated Show resolved Hide resolved
deps/common/src/logseq/common/path_test.cljs Outdated Show resolved Hide resolved
src/electron/electron/utils.cljs Show resolved Hide resolved
@andelf
Copy link
Collaborator Author

andelf commented Mar 16, 2023

UPDATE: There won't be more functional and refactoring commits.
I'll fix the CI tests.

@cnrpman
Copy link
Collaborator

cnrpman commented Mar 16, 2023

About the E2E CI failure:
During onboarding, when attempting to bypass the file selector using the MOCKED_OPEN_DIR_PATH var in E2E, the behavior is not expected.
Can be test via:

  1. Clear cache
  2. Set the window.MOCKED_OPEN_DIR_PATH value to "/Users/jun/git/lambda", by executing following in console:
window.__MOCKED_OPEN_DIR_PATH__ = "/Users/jun/git/lambda"
  1. Mouse click "choose a folder"

The behavior on the master branch is normal, but it is wrong in the pull request.

Related code:

#?(:cljs
(defn mocked-open-dir-path
"Mocked open DIR path for by-passing open dir in electron during testing. Nil if not given"
[]
(when (electron?) (. js/window -__MOCKED_OPEN_DIR_PATH__))))

Copy link
Collaborator

@logseq-cldwalker logseq-cldwalker left a comment

Choose a reason for hiding this comment

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

@andelf Thanks for taking on this necessary and tricky refactor. I haven't finished reviewing this large PR but figured I'd share my feedback so far

@@ -155,6 +156,7 @@

(defn- get-file-absolute-path
[config path]
(js/console.error "TODO: buggy path fn")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will remove this in the next PR.

(->> (take-last 2 (string/split repo-url #"/"))
(string/join "_")))))
(do
(js/console.error "BUG: This should be unreachable! get-repo-dir" repo-url)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this shouldn't happen, should we also notify sentry so we know this is happening?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a notification to devs, not a fatal error. To standardize the use of get-repo-dir.

src/main/frontend/config.cljs Show resolved Hide resolved
src/main/frontend/config.cljs Outdated Show resolved Hide resolved
src/main/frontend/core.cljs Show resolved Hide resolved
src/main/frontend/fs/memory_fs.cljs Outdated Show resolved Hide resolved
src/main/frontend/fs.cljs Show resolved Hide resolved
@@ -0,0 +1,302 @@
(ns logseq.common.path
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's great we're trying to improve file and path handling. However, this is the 3rd major approach to file and path handling after frontend.util/node-path.* and the npm path library. Without some documentation it's unclear when to use which approach. Could you write some docs on when to use this ns? Some questions that would be helpful to answer in docs:

  • Is there a plan to deprecate the other approaches and if so, what is it?
  • When to use filename vs util/node-path.basename?
  • When to use file-ext vs gp-util/path->file-ext?
  • When to use path-join vs util/node-path.join or node-path/join? What type of paths should we not use join for? I've seen relative paths like logseq/config.edn aren't using it so maybe it's only for full paths?
  • What platforms do these fns support? For example, is relative-path mostly for mobile since it's replacing capacitor-fs/replacing normalize-file-protocol-path?

@@ -0,0 +1,27 @@
(ns logseq.common.path-test
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add tests for more of the main fns? Perhaps some of the deleted tests of capacitor-fs-test can be reused. I'd be hesitant to use this library going forward if there's little shared understanding of what the expected behavior is. I can help with desktop tests if you'd like

src/main/frontend/handler/global_config.cljs Show resolved Hide resolved
@logseq-cldwalker
Copy link
Collaborator

@andelf Added a commit to setup tests and fix minor stuff. Just trying to help on workflow so feel free to change it if you have a preferred setup. Should be able to do QA and finish review tomorrow

Copy link
Collaborator

@logseq-cldwalker logseq-cldwalker left a comment

Choose a reason for hiding this comment

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

@andelf QAed desktop and browser and it works great except for config issues. I fixed global config issues I was seeing. I see that config editing fails to open in the browser and confirmed this was occurring before my commits. Back to you for that bug and some comments. Can help with desktop tests tomorrow if you'd like

src/main/frontend/db/model.cljs Outdated Show resolved Hide resolved
@@ -1,6 +1,6 @@
(ns frontend.handler.file-sync
"Provides util handler fns for file sync"
(:require ["path" :as path]
(:require ["path" :as node-path]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good idea to rename to avoid having conflict aliases. Happy to finish doing these renames in a follow up PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change estimate: large Require major refactor of a feature help-wanted Need help from people with specific environment or konwledge :type/bug-fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants