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

Some fixes and improvements for the articles feature #1976

Merged
merged 8 commits into from
Aug 1, 2024

Conversation

caiosba
Copy link
Contributor

@caiosba caiosba commented Jul 31, 2024

Description

  • Don't include blank media in search queries (lists and counts)
  • Update item title when fact-check is updated
  • Filter out explainers already applied to the item
  • Index explainer titles in addition to summary paragraphs

Reference: CV2-5000.

Checklist

  • I have performed a self-review of my own code
  • I have added unit and feature tests, if the PR implements a new feature or otherwise would benefit from additional testing
  • I have added regression tests, if the PR fixes a bug
  • I have added logging, exception reporting, and custom tracing with any additional information required for debugging
  • I considered secure coding practices when writing this code. Any security concerns are noted above.
  • I have commented my code in hard-to-understand areas, if any
  • I have made needed changes to the README
  • My changes generate no new warnings
  • If I added a third party module, I included a rationale for doing so and followed our current guidelines

@caiosba caiosba marked this pull request as ready for review August 1, 2024 01:56
@@ -153,7 +153,7 @@ def get_title
return self.send(title_mapping[title_field]).to_s
end
title = self.original_title
[self.analysis['file_title'], self.analysis['title'], self.fact_check_title, self.claim_description_content].each do |value|
[self.analysis['file_title'], self.analysis['title'], self.fact_check_title(true), self.claim_description_content].each do |value|
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 for self.fact_check_title(true) we should not call cached field with true to enforce regenerate cached field and make sure that cached field updated in relevant actions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a race condition so I had to force that refresh... the event was triggering a call to this method, so it would fail.

@@ -174,7 +174,7 @@ def media_slug
end

def get_description
return self.fact_check_summary if self.get_main_channel == CheckChannels::ChannelCodes::FETCH
return self.fact_check_summary(true) if self.get_main_channel == CheckChannels::ChannelCodes::FETCH
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 for self.fact_check_summary(true) we should not call cached field with true to enforce regenerate cached field and make sure that cached field updated in relevant actions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a race condition so I had to force that refresh... the event was triggering a call to this method, so it would fail.

@@ -497,6 +497,9 @@ def filtered_explainers(filters = {})
# Filter by text
query = query.where('(title ILIKE ? OR url ILIKE ? OR description ILIKE ?)', *["%#{filters[:text]}%"]*3) if filters[:text].to_s.size > 2

# Exclude the ones already applied to a target item
query = query.where.not(id: ProjectMedia.find(filters[:target_id].to_i).explainer_ids) unless ProjectMedia.find_by_id(filters[:target_id].to_i).nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not know if the ProjectMedia with filters[:target_id] exist this means that the query to find the ProjectMedia item will run twice one to check that item exists and the second one for the original query
if yes I think it's better to get the object then do our check
i.e
pm = ProjectMedia.find_by_id(filters[:target_id].to_i)
query = query.where.not(id: pm.explainer_ids) unless pm.nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, done!

@@ -533,6 +536,9 @@ def filtered_fact_checks(filters = {})
# Filter by text
query = query.where('(fact_checks.title ILIKE ? OR fact_checks.url ILIKE ? OR fact_checks.summary ILIKE ?)', *["%#{filters[:text]}%"]*3) if filters[:text].to_s.size > 2

# Exclude the ones already applied to a target item
query = query.where.not('fact_checks.id' => ProjectMedia.find(filters[:target_id].to_i).fact_check_id) unless ProjectMedia.find_by_id(filters[:target_id].to_i).nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

if the query run twice in case the item exists then I suggest to do the following:
pm = ProjectMedia.find_by_id(filters[:target_id].to_i)
query = query.where.not('fact_checks.id' => pm.fact_check_id) unless pm.nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, done!

@caiosba caiosba requested a review from melsawy August 1, 2024 12:52
@caiosba
Copy link
Contributor Author

caiosba commented Aug 1, 2024

@melsawy, thanks for your comments - please re-review.

@caiosba caiosba merged commit f3c18a0 into develop Aug 1, 2024
9 of 10 checks passed
@caiosba caiosba deleted the fixes/CV2-5000-articles branch August 1, 2024 13:24
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