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

Create API for research search #3987

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

Conversation

goratt12
Copy link
Collaborator

@goratt12 goratt12 commented Nov 5, 2024

PR Checklist

PR Type

What kind of change does this PR introduce?

  • Bugfix (fixes an issue)
  • Feature (adds functionality)
  • Code style update
  • Refactoring (no functional changes)
  • Build related changes
  • CI related changes
  • Documentation changes
  • Other... Please describe:

What is the current behavior?

Fetching of research articles is being done directly with Firestore

What is the new behavior?

Fetching of research articles have moved to a Remix backend API

If useful, provide screenshot or capture to highlight main changes

Does this PR introduce a breaking change?

  • Yes
  • No

Git Issues

Closes #3924

What happens next?

Thanks for the contribution! We try to make sure all PRs are reviewed ahead of our monthly maintainers call (first Monday of the month)

If the PR is working as intended it'll be merged and included in the next platform release, if not changes will be requested and re-reviewed once updated.

If you need more immediate feedback you can try reaching out on Discord in the Community Platform development channel.

@goratt12 goratt12 requested a review from a team as a code owner November 5, 2024 19:46
Copy link

cypress bot commented Nov 8, 2024

onearmy-community-platform    Run #6538

Run Properties:  status check failed Failed #6538  •  git commit 8760cc630c: fix: fix PR reviews
Project onearmy-community-platform
Branch Review pull/3987
Run status status check failed Failed #6538
Run duration 05m 37s
Commit git commit 8760cc630c: fix: fix PR reviews
Committer unknown
View all properties for this run ↗︎

Test results
Tests that failed  Failures 2
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 70
View all changes introduced in this branch ↗︎

Tests for review

Failed  settings.spec.ts • 1 failed test • ci-chrome

View Output Video

Test Artifacts
[Settings] > [Fixing Fashion] > Can create member Test Replay Screenshots Video
Failed  map.spec.ts • 1 failed test • ci-chrome

View Output Video

Test Artifacts
[Map] > [Shows expected pins] Test Replay Screenshots Video
Flakiness  src/integration/research/follow.spec.ts • 1 flaky test • ci-chrome

View Output Video

Test Artifacts
[Research] > [By Authenticated] > [Follow button] Test Replay Screenshots Video


describe('research.service', () => {
describe('search', () => {
it('fetches research articles based on search criteria', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

these tests aren't very useful now, because it's just mocking and checking the mocked value, so not testing anything real.
we should instead add cypress and/or UI tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Im on it :)

constraints = [...constraints, sortConstraint]
try {
const response = await fetch(
`/api/research?words=${words.join(',')}&category=${category}&sort=${sort}&status=${status ?? ''}&last_doc_id=${lastDocId ?? ''}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, thank you for the idea


import type { ICategory } from 'oa-shared'

const cache = new Keyv<ICategory[]>({ ttl: 600000 }) // ttl: 10 minutes
Copy link
Contributor

Choose a reason for hiding this comment

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

this rarely changes, should increase for at least 1h

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

export const loader = async ({ request }) => {
const url = new URL(request.url)
const searchParams = url.searchParams
const userId: string | null = searchParams.get('user_id')
Copy link
Contributor

Choose a reason for hiding this comment

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

these params are usualy camelCase, so userId

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, on the API side as well

export const loader = async () => {
const cachedCategories = await cache.get('researchCategories')

// check if cached map pins are availbe, if not - load from db and cache them
Copy link
Contributor

Choose a reason for hiding this comment

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

map pins

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oops :)

const cachedCategories = await cache.get('researchCategories')

// check if cached map pins are availbe, if not - load from db and cache them
if (cachedCategories) return json({ categories: cachedCategories })
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the brackets

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What brackets do you mean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

[Tech] Create API for research search
2 participants