-
Notifications
You must be signed in to change notification settings - Fork 81
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
DEV: Move solved custom fields into a table #342
Conversation
bb8160b
to
7d6611d
Compare
db/migrate/20250318025147_add_index_for_discourse_solved_topics.rb
Outdated
Show resolved
Hide resolved
db/migrate/20250318025147_add_index_for_discourse_solved_topics.rb
Outdated
Show resolved
Hide resolved
db/migrate/20250318024953_copy_solved_topic_custom_field_to_discourse_solved_solved_topics.rb
Show resolved
Hide resolved
db/migrate/20250318024953_copy_solved_topic_custom_field_to_discourse_solved_solved_topics.rb
Outdated
Show resolved
Hide resolved
087f947
to
ba32049
Compare
`/categories` sometimes returns accompanying topics under certain site settings. The `CategoryList` currently allows preloading for topic custom fields via `preloaded_topic_custom_fields`, but not for topics themselves. This addition is required for discourse/discourse-solved#342.
b6c14fb
to
75ad157
Compare
|
||
topic_view_post_custom_fields_allowlister { [::DiscourseSolved::IS_ACCEPTED_ANSWER_CUSTOM_FIELD] } | ||
TopicList.preloaded_custom_fields << ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD | ||
register_category_list_topics_preloader_associations(:solved) if SiteSetting.solved_enabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API is not yet available on the stable
branch so we need to update the plugins compatibility file.
spec/models/solved_topics_spec.rb
Outdated
@@ -0,0 +1,66 @@ | |||
# frozen_string_literal: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just dropping a note to remove this before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me 👍 Do add a .plugin-compatibility
file before merging :)
.discourse-compatibility
Outdated
< 3.5.0.beta2-dev: e82c6ae1ca38ccebb34669148f8de93a3028906e | ||
3.4.1: e82c6ae1ca38ccebb34669148f8de93a3028906e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SHA before this PR in this plugin is e82c6ae1ca38ccebb34669148f8de93a3028906e
.
Current discourse version is 3.4.1 and 3.5.0.beta2.
#342 was deployed and observed to only have 5000 (batch size) migrated. This is an error in migration where the ids had a gap between the batch. This PR changes the migration to just loop through all topic custom fields with each loop increasing by batch size.
Depends on: #342 This feature adds the "Marked solved as" information to the solved post appended to OP. Originally, I had moved the widget usage to a [component](https://github.com/discourse/discourse-solved/blob/39baa0be4a889fdbff108e887a677d9a298d27d4/assets/javascripts/discourse/components/solved-post.gjs), but due to "cooking quotes", after some internal discussion (t/95318/25) we will stick to widgets for now as the post-stream gets modernized.
`/categories` sometimes returns accompanying topics under certain site settings. The `CategoryList` currently allows preloading for topic custom fields via `preloaded_topic_custom_fields`, but not for topics themselves. This addition is required for discourse/discourse-solved#342.
This commit solves a few issues: - Currently due to the 14.day schedule, any sites with `remind_mark_solution_last_post_age` of 1 will not be able to receive notifications. This bumps the frequency to a day - On a site with hundreds of thousands of topics, this loads all the ids into memory `unsolved_topic_ids.push(*Topic.where(category_id: category_ids).pluck(:id))` 😱 - Many plucks (N+1) - (Potentially) Large array subtractions are inefficient and could be done in the database - Moves to custom fields as per discourse/discourse-solved#342
As part of the custom fields to table move for discourse-solved (discourse/discourse-solved#342), we need to update the query here
) Before discourse/discourse-solved#342, scorables for solved were in custom fields, this means no errors or validations were required since every instance is able to query custom fields. Now we will have to check for the availability of discourse_solved prior to scoring. This commit disables the scorable if the plugin is not enabled or installed.
This update might break discourse during migration, if for some reason two posts link to the same resolved topic. |
As part of #342, some discrepancies in the old implementation resulted in solved topics linking to posts that do not exist (dangling custom field value). Causing us to see the following when there are no `answer_post` ``` NoMethodError (undefined method `user' for nil) ``` This PR prevents the error.
Related:
Requires:
This PR converts all use of post and topic custom fields into a dedicated table:
This PR does not attempt to fix issues or optimise, and does not delete old data from custom fields yet.