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

Migrate get evaluations query to Drizzle on API Frontend #160

Conversation

haikalvidya
Copy link
Contributor

@haikalvidya haikalvidya commented Nov 5, 2024

closed #81


Important

Migrated evaluation fetching logic to Drizzle ORM on the frontend, removing old SQLX-based backend implementation.

  • Backend Removal:
    • Removed get_evaluation_datapoint function from evaluations.rs.
    • Removed get_evaluation_datapoint service from main.rs.
  • Frontend Migration:
    • Deleted route.ts for datapoints under frontend/app/api/projects/[projectId]/evaluations/[evaluationId].
    • Updated route.ts for evaluations to use Drizzle ORM for fetching evaluations and results.
    • Updated page.tsx to fetch evaluation info and evaluations using new API endpoints.
  • API Changes:
    • Added Drizzle ORM queries in route.ts for fetching evaluations and results.
    • Added user membership check in route.ts for evaluations.
    • Updated get_evaluations to handle groupId filtering in route.ts.

This description was created by Ellipsis for f9ebdd8. It will automatically update as commits are pushed.

@CLAassistant
Copy link

CLAassistant commented Nov 5, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ haikalvidya
✅ dinmukhamedm
❌ Vidya Haikal


Vidya Haikal seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@haikalvidya haikalvidya force-pushed the refac/migrate-evaluations-query-to-drizzle branch from 2f7bbb3 to dc9eb13 Compare November 5, 2024 17:21
Copy link
Member

@dinmukhamedm dinmukhamedm left a comment

Choose a reason for hiding this comment

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

LGTM overall, though left small comments. Regarding the deletion you mentioned: it is fine to only delete the unused frontend code. If you feel like setting up rust and building app-server is a little too much, we will remove the redundant backend code ourselves

Comment on lines 28 to 44
filters: [],
baseQuery,
orderBy: desc(sql`created_at`),
});
return Response.json(result);
} else {
const baseQuery = db.$with('base').as(db.select().from(evaluations));

return Response.json(result);
const result = await paginatedGet<any, Evaluation>({
table: evaluations,
baseFilters: [eq(sql`project_id`, projectId)],
filters: [],
baseQuery,
orderBy: desc(sql`created_at`)
});
Copy link
Member

Choose a reason for hiding this comment

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

we've simplified paginated get a bit, sorry about that. If you could pull/merge the latest dev into your branch? It now looks like this:

  const result = await paginatedGet<any, Evaluation>({
    table: evaluations,
    filters: [eq(evaluations.projectId, projectId)],
    orderBy: desc(evaluations.createdAt),
  });

frontend/app/api/projects/[projectId]/evaluations/route.ts Outdated Show resolved Hide resolved
Vidya Haikal and others added 2 commits November 6, 2024 17:11
# Conflicts:
#	frontend/app/api/projects/[projectId]/evaluations/route.ts
@haikalvidya haikalvidya force-pushed the refac/migrate-evaluations-query-to-drizzle branch from 8023955 to 8a0fdb3 Compare November 6, 2024 10:32
@dinmukhamedm
Copy link
Member

Thanks @haikalvidya, amazing work! This looks good to me. Let me know once/if you've tested this

@haikalvidya haikalvidya marked this pull request as ready for review November 8, 2024 17:59
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to f9ebdd8 in 1 minute and 7 seconds

More details
  • Looked at 368 lines of code in 7 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. frontend/app/api/projects/[projectId]/evaluations/route.ts:69
  • Draft comment:
    The DELETE function does not execute the delete operation. You need to call .execute() to perform the deletion. Consider adding:
      .execute()
  • Reason this comment was not posted:
    Comment was on unchanged code.

Workflow ID: wflow_Y0siwNPKFaxaIofL


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

filters: [eq(evaluations.projectId, projectId)],
orderBy: desc(evaluations.createdAt),
});
if (groupId && !groupId.trim()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The condition if (groupId && !groupId.trim()) seems incorrect. It should check if groupId is not empty after trimming. Consider changing it to:

Suggested change
if (groupId && !groupId.trim()) {
if (groupId && groupId.trim())

@haikalvidya
Copy link
Contributor Author

Hey @dinmukhamedm sorry for late response, I haven't been able to test the changes yet due to some reasons (I DM'ed you about it on discord). However, I think the code is ready for review.

}
}
const evaluationInfoRes = await fetch(
`/api/projects/${params.projectId}/evaluations/${params.evaluationId}`
Copy link
Member

Choose a reason for hiding this comment

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

@haikalvidya sorry, hadn't realized at first, but this will neither compile nor we should keep it here. Let's move the logic from the routes directly to this file (as util functions) and remove the API routes if they are unused. Also, please address the Ellipsis comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oohh, alright, will work on that today

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you kindly review my latest commit again?, i have tested the changes, and it is running well

Copy link
Collaborator

@skull8888888 skull8888888 left a comment

Choose a reason for hiding this comment

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

qq: did you test everything locally?

@@ -22,20 +26,82 @@ export default async function EvaluationPage({
redirect('/sign-in');
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can remove this (and its imports), middleware now protects all project/* and projects/* routes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i have updated the code upon this matter

Copy link
Member

@dinmukhamedm dinmukhamedm left a comment

Choose a reason for hiding this comment

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

Excellent work! Thanks!

@dinmukhamedm dinmukhamedm merged commit ee7dee6 into lmnr-ai:dev Nov 10, 2024
1 check was pending
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.

4 participants