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

Optimize Query in Quizzes #10

Open
Nottommy11 opened this issue Sep 23, 2023 · 1 comment
Open

Optimize Query in Quizzes #10

Nottommy11 opened this issue Sep 23, 2023 · 1 comment
Assignees
Labels
Enhancement New feature or request Good First Issue Good for newcomers GQL Requires work done with gql queries/mutations JavaScript Requires work done in JavaScript

Comments

@Nottommy11
Copy link
Member

Navigate to the +page.svelte in Quizzes.

Optimize the queries in the getQuestionsCount and getQuestions functions so they are easier to read and use the netLvl variable to make the queries.

Here is an example:

const myres = client.query({
	Method: 'POST',
	query: gql`
		query getNet${netLvl}QuestionsCount {
			net_${netLvl}_net_questions_aggregate {
				aggregate {
					count
				}
			}
		}
	`
});

return (await myres).data[`net_${netLvl}_net_questions_aggregate`].aggregate.count;

So basically, we don't want to use the if statements checking netLvl anymore.

@Nottommy11 Nottommy11 added Enhancement New feature or request Good First Issue Good for newcomers JavaScript Requires work done in JavaScript GQL Requires work done with gql queries/mutations labels Sep 23, 2023
@kyphillips
Copy link
Collaborator

Can we do this by just having a single query variable that looks for the level, like this

async function getQuestionsCount() {
try {
const myres = client.query({
Method: 'POST',
query: gqlquery getQuestionsCount($netLvl: Int) { net_questions_aggregate(where: {net_level: {_eq: $netLvl}}){ aggregate { count } } },
variables: {
netLvl: netLvl
}
});

	return (await myres).data.net_questions_aggregate.aggregate.count;
} catch (err) {
	console.log(err);
}

}

@kyphillips kyphillips self-assigned this Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Good First Issue Good for newcomers GQL Requires work done with gql queries/mutations JavaScript Requires work done in JavaScript
Projects
None yet
Development

No branches or pull requests

2 participants