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(9586): implement freetext search in cht datasource #9625

Open
wants to merge 81 commits into
base: master
Choose a base branch
from

Conversation

sugat009
Copy link
Member

@sugat009 sugat009 commented Nov 7, 2024

Description

Closes: #9586

Code review checklist

  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or e2e where appropriate
  • Internationalised: All user facing text
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.

Compose URLs

If Build CI hasn't passed, these may 404:

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

@sugat009 sugat009 linked an issue Nov 7, 2024 that may be closed by this pull request
@sugat009 sugat009 force-pushed the 9586-implement-freetext-search-in-cht-datasource branch from eba7aac to 43efbef Compare November 18, 2024 08:59
@sugat009
Copy link
Member Author

@jkuester I did not go with the hook implementation as it would mean checking for filenames to run because this auth setup needs to run only for a few test suites, which would have resulted in a not-so-fruitful hook file with checks.

@sugat009 sugat009 requested a review from jkuester January 17, 2025 07:56
Copy link
Contributor

@jkuester jkuester left a comment

Choose a reason for hiding this comment

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

Alright! We are getting very close here.

shared-libs/cht-datasource/src/contact.ts Outdated Show resolved Hide resolved
shared-libs/cht-datasource/src/contact.ts Outdated Show resolved Hide resolved
shared-libs/cht-datasource/src/index.ts Outdated Show resolved Hide resolved
shared-libs/cht-datasource/src/index.ts Outdated Show resolved Hide resolved
shared-libs/cht-datasource/src/qualifier.ts Outdated Show resolved Hide resolved
shared-libs/cht-datasource/src/local/libs/lineage.ts Outdated Show resolved Hide resolved
};

/** @internal */
export const getContactLineage = (medicDb: PouchDB.Database<Doc>) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: I guess now the getPrimaryContactIds, hydratePrimaryContact, hydrateLineage functions do not need to be exported since they are only getting used in this file.

shared-libs/cht-datasource/src/local/report.ts Outdated Show resolved Hide resolved
tests/integration/shared-libs/cht-datasource/auth.js Outdated Show resolved Hide resolved
@sugat009 sugat009 requested a review from jkuester February 6, 2025 05:18
Copy link
Contributor

@jkuester jkuester left a comment

Choose a reason for hiding this comment

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

Lets 👏 freaking 👏 go 👏 !!!!! 🚀 🚀

Thanks @sugat009 for hanging in with me on this absolute tour-de-force! 💪

shared-libs/cht-datasource/src/index.ts Outdated Show resolved Hide resolved
shared-libs/cht-datasource/src/index.ts Outdated Show resolved Hide resolved
shared-libs/cht-datasource/src/index.ts Outdated Show resolved Hide resolved
@@ -155,19 +155,45 @@ export const fetchAndFilter = <T extends Doc>(
};

/** @internal */
export const getPaginatedDocs = async <T>(
getDocsFn: (limit: number, skip: number) => Promise<Nullable<T>[]>,
export const fetchAndFilterUuids = (
Copy link
Contributor

Choose a reason for hiding this comment

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

note: I am fine going with whatever way you think is most maintainable, but I originally was thinking we could re-use the existing fetchAndFilter function instead of duplicating most of that logic again here... 😬

export const fetchAndFilterUuids = (
  getFunction: (limit: number, skip: number) => Promise<string[]>,
  limit: number,
): ReturnType<typeof fetchAndFilter<string>> => {
  const uuidSet = new Set<string>();
  const filterFn = (uuid: Nullable<string>): boolean => {
    if (!uuid) {
      return false;
    }
    const { size } = uuidSet;
    uuidSet.add(uuid);
    return uuidSet.size !== size;
  };

  return fetchAndFilter(
    getFunction,
    filterFn,
    limit
  );
};

I see you have a + 1 fetch in your fetchAndFilterUuids which is a bit different behavior (but maybe that should be built into the base fetchAndFilter? Otherwise, I do not see much performance difference between these right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, there is no performance difference between these two. I implemented this function separately because when I started working on this I saw a situation, not a bug I guess, where if you query with limit 10. There are 10 objects in the database, the cursor is also returned as 10, which means the end-user might re-query again, and then in the next request the user gets cursor as null, resulting in 1 extra query. The +1 way is a solution for that.

I did not implement the +1 way directly into the already-existing fetchAndFilter functionality because it might affect the places where it is used but now that I think about fetchAndFilter VS fetchAndFilterUuids, they have a bit of an inconsistent cursor returns. I think implementing fetchAndFilterUuids the above way and re-doing fetchAndFilter with the +1 functionality could be done. However, I think we can move on with the above suggestion and keep the +1 way as a future enhancement as it's not a breaking issue. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can move on with the above suggestion and keep the +1 way as a future enhancement as it's not a breaking issue. What do you think?

Sounds good! 👍

@mrjones-plip
Copy link
Contributor

Lets 👏 freaking 👏 go 👏 !!!!! 🚀 🚀

YYYYYYYYEEEESSS!!! you two are amazing - so great to see this work come together

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.

Implement freetext search in cht-datasource
4 participants