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

#38 - Query performance and Database setup script - Appolin Semegni Fotso #54

Merged
merged 12 commits into from
Oct 19, 2023

Conversation

AppolinFotso
Copy link
Contributor

@AppolinFotso AppolinFotso commented Oct 18, 2023

Naming Rules

Name your PR like this: ISSUENUMBER-TITLE-YOURNAME

Description

I removed the getRandomIndex function in api.js file. I changed how the database is queried for a random sentence by using the ORDER BY random() and LIMIT 1 clauses.
I updated the database schema and the type of data stored in the selected_suggestion column in the user_interactions table.
I updated the codebase to reflect the database schema.
I added a state for the randomTextId and removed unnecessary query on the /save-seggestions endpoint.

Related to

Make sure you include the issue number with a hash sign # so Github can link this PR to the right issue, like this:

Fixes #38

Checklist:

  • My code follows the style guidelines of this project
  • I have carefully reviewed my own code
  • I have commented my code
  • I have updated any documentation

@render
Copy link

render bot commented Oct 18, 2023

@render
Copy link

render bot commented Oct 18, 2023

@@ -14,20 +16,20 @@ CREATE TABLE suggestions (
CREATE TABLE user_interactions (
id SERIAL PRIMARY KEY,
sentence_id INTEGER REFERENCES sentences(id),
selected_suggestion TEXT,
selected_suggestion INTEGER,
Copy link
Contributor

Choose a reason for hiding this comment

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

This change needs the relevant change in the codebase, currently the system will try to save the textual value, which will be converted to 0

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 changed the codebase to reflect the schema. Please let me know if I have taken the right approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this looks good, Going to verify it locally

@sztupy
Copy link
Contributor

sztupy commented Oct 18, 2023

Rest of the changes look okay for now!

@AppolinFotso AppolinFotso requested a review from sztupy October 18, 2023 15:13
@AppolinFotso AppolinFotso marked this pull request as ready for review October 18, 2023 15:58
server/api.js Outdated
const randomSentence = oneRow.rows[0].sentence;
const randomSentenceId = oneRow.rows[0].id;
// Send randomSentence to frontend;
res.json([randomSentence, randomSentenceId]);
Copy link
Contributor

@sztupy sztupy Oct 19, 2023

Choose a reason for hiding this comment

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

Prefer returning objects:

{
  sentence: randomSentence,
  id: randomSentenceId
}

…and_query-performance

* origin/main:
  state is not updated if user is authorized
  submit button is disabled, if auth prompt is fired
  removed console.log, changed submitCounter to 4
  passing props from Home.js
  add counter and login dialog fire logic
  add Dialog Popup Window
  changed navbar depending on user authorization
  removed redirect if user is no authorized
  add format on save to be true
Copy link
Contributor

@sztupy sztupy left a comment

Choose a reason for hiding this comment

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

There is a bug when using the "none of the suggestions are useful" and the "original sentence is correct" buttons - the sentence ID is not stored in the database:

cyf=# select * from user_interactions;
 id | sentence_id | selected_suggestion | user_provided_suggestion | original_sentence_was_correct
----+-------------+---------------------+--------------------------+-------------------------------
  1 |           5 |                   1 |                          |
  2 |           4 |                   5 |                          |
  3 |           5 |                   9 |                          |
  4 |             |                     |                          | t
  5 |             |                     | own correction           |
(5 rows)

As you can se rows 4 & 5 are missing the sentenceId values.

Rest of the code looks to be working and is what is expected!

@sztupy
Copy link
Contributor

sztupy commented Oct 19, 2023

Do note I have merged in main, so when you continuw orking make sure to pull this branch first

@AppolinFotso
Copy link
Contributor Author

I did not check those two buttons because they were not part of the ticket and I thought someone else was working on them.
I am at work at the moment but I will check them when I get home this evening. Thanks

@sztupy
Copy link
Contributor

sztupy commented Oct 19, 2023

Hi, the ticket didn't mention them as they didn't exist yet. They were added since, and functionality wise they should remain working for any feature we merge afterwards - otherwise we cause a regression and a loss of feature.

Note: if you need to redesign their UX to be more in line with how the other buttons work that won't be a problem (specifically the "Correct" button looks a bit too convoluted)

@AppolinFotso
Copy link
Contributor Author

The sentence ID is now stored in the user_interactions table when either of the two buttons is clicked.

@sztupy
Copy link
Contributor

sztupy commented Oct 19, 2023

Couple minor issues, but I'll address them later, the code looks to be working now and does what is expected

@sztupy sztupy merged commit e654882 into main Oct 19, 2023
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.

2 participants