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

Project List API updates for UCM Desktop #5553

Draft
wants to merge 8 commits into
base: trunk
Choose a base branch
from

Conversation

ChrisPenner
Copy link
Contributor

@ChrisPenner ChrisPenner commented Jan 21, 2025

Overview

Resolves:

Handles:

Implementation notes

  • ADDS A SCHEMA MIGRATION to add a last_accessed unix epoch column to theproject_branch which is set when setCurrentProjectPath is called (which is whenever the user switches).
  • Splits of a Utils module in SQLite and moves likeEscape there.
  • I made a new Query module in unison-share-api for UCM local queries, since these will likely be pretty different than UCM's internal queries over time. If we'd really prefer ALL queries be in the same module I can move it.
  • Allows filtering project or branch listings by an infix query rather than JUST a prefix one.
  • Made a new query for project listings which includes the last active branch name and sorts by that branch's most recently accessed time.

Interesting/controversial decisions

How do we want to organize query modules and things for UCM Desktop?

Test coverage

Updated api transcript tests.

@ChrisPenner ChrisPenner force-pushed the cp/project-list-updates branch from 8ab42ff to 5017678 Compare January 21, 2025 20:11
Comment on lines -2277 to -2302
-- | Escape special characters for "LIKE" matches.
--
-- Prepared statements prevent sql injection, but it's still possible some user
-- may be able to craft a query using a fake "hash" that would let them see more than they
-- ought to.
--
-- You still need to provide the escape char in the sql query, E.g.
--
-- @@
-- SELECT * FROM table
-- WHERE txt LIKE ? ESCAPE '\'
-- @@
--
-- >>> likeEscape '\\' "Nat.%"
-- "Nat.\%"
likeEscape :: Char -> Text -> Text
likeEscape '%' _ = error "Can't use % or _ as escape characters"
likeEscape '_' _ = error "Can't use % or _ as escape characters"
likeEscape escapeChar pat =
flip Text.concatMap pat \case
'%' -> Text.pack [escapeChar, '%']
'_' -> Text.pack [escapeChar, '_']
c
| c == escapeChar -> Text.pack [escapeChar, escapeChar]
| otherwise -> Text.singleton c

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to Unison.Sqlite.Utils

Comment on lines +94 to +106
initializeCurrentProjectPath :: ProjectId -> ProjectBranchId -> [NameSegment] -> Sqlite.Transaction ()
initializeCurrentProjectPath projId branchId path = do
Sqlite.execute
[Sqlite.sql| DELETE FROM current_project_path |]
Sqlite.execute
[Sqlite.sql|
INSERT INTO current_project_path(project_id, branch_id, path)
VALUES (:projId, :branchId, :jsonPath)
|]
where
jsonPath :: Text
jsonPath =
Text.Lazy.toStrict (Aeson.encodeToLazyText $ NameSegment.toUnescapedText <$> path)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Froze this code via copy-pasta since it's part of a migration and shouldn't change.

@ChrisPenner ChrisPenner removed the request for review from aryairani January 21, 2025 23:02
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.

1 participant