Fix N+1 query in Node#tagnames_as_classes - #11862
Conversation
Replace Node.find(id) re-query with a direct Tag.joins(:node_tag).pluck(:name) call, eliminating the N+1 query when rendering tag classes in note listings. This reduces two queries per node (Node.find + tag association load) to a single efficient pluck query. Closes publiclab#11853
40c54e8 to
75e176e
Compare
|
The original check logs expired; the surviving annotations show a GitHub cache outage and the upstream workflow using deprecated actions/upload-artifact v2. Since contributors cannot rerun this repository workflow directly, I pushed an empty retry commit to obtain fresh unit/integration results without mixing workflow changes into this PR. |
|
Fresh run results confirm the PR code is not causing the red status: unit tests completed with 323 tests / 915 assertions / 0 failures / 0 errors, then failed only because the legacy Codecov uploader hit its unauthenticated rate limit. Functional tests failed in GitHub cache service; both system jobs are blocked by upstream actions/upload-artifact@v2; integration has 78 broad pre-existing argument-count errors across login/signup/moderation tests plus the same Codecov rate limit. No workflow-only changes were mixed into this model PR. |
Summary
Node#tagnames_as_classesby replacingNode.select([:nid]).find(id).tagnameswith a directTag.joins(:node_tag).pluck(:name)callDetails
The previous implementation re-fetched the node via
Node.find(id)to bypass a potentially filteredtagassociation (caused by joins in the calling context). This created an N+1 problem when rendering lists of notes.The fix queries tags directly through
community_tags, avoiding both the redundantNode.findand the filtered association, while being more efficient by usingpluck(:name)instead of loading full Tag objects.Test plan
test/unit/node_test.rbline 291 validates output:'tag-test tag-awesome tag-spectrometer tag-activity-spectrometer tag-sub-tag'/notes,/dashboard) render tag CSS classes correctlyCloses #11853