<p></p>
<p><b>@grekko</b> commented on this pull request.</p>
<hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4481#discussion_r1768000518">app/models/note/migrate_opened_comment.rb</a>:</p>
<pre style='color:#555'>> +
+ def call
+ return false if skip?
+
+ attributes = opened_comment_note.attributes.slice(*%w[body author_id author_ip]).compact_blank
+ @note.update_columns(attributes) # rubocop:disable Rails/SkipsModelValidations
+ end
+
+ def skip?
+ opened_comment_note.blank?
+ end
+
+ private
+
+ def opened_comment_note
+ @note.comments.unscope(:where => :visible).find_by(:event => "opened")
</pre>
<p dir="auto">Thanks for taking a close look here. I agree with your concerns regarding the data integrity.</p>
<blockquote>
<p dir="auto">[…] rework it to only be concerned about the first comment.</p>
</blockquote>
<p dir="auto">Yup. This will simplify things and keep the behaviour identical. I will update the PR to reflect this.</p>
<hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4481#discussion_r1768099353">app/controllers/notes_controller.rb</a>:</p>
<pre style='color:#555'>> @@ -37,6 +37,9 @@ def show
@note = Note.visible.find(params[:id])
@note_comments = @note.comments
end
+
+ # FIXME: notes_refactoring remove this once the backfilling is completed
+ @note_comments = @note_comments.reject { |comment| comment.event == "opened" } unless @note.body_migrated?
</pre>
<p dir="auto">Will change to simply <code class="notranslate">@note_comments = @note_comments.drop(1)</code> since we'll only look at the first comment and ignore the <code class="notranslate">event</code> when migrating the data.</p>
<hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4481#discussion_r1771269930">app/models/note.rb</a>:</p>
<pre style='color:#555'>> @@ -39,6 +49,10 @@ class Note < ApplicationRecord
DEFAULT_FRESHLY_CLOSED_LIMIT = 7.days
+ def comments_with_extra_open_comment
</pre>
<blockquote>
<p dir="auto">Is this required in the model?</p>
</blockquote>
<p dir="auto">I think its needed for the behaviour of the API NotesController.</p>
<blockquote>
<p dir="auto">[…] and then note.comments which would return either N (if body migrated) or N-1 (if body not migrated) comments</p>
</blockquote>
<p dir="auto">I understand you are suggesting to implement a custom <code class="notranslate">Note#comments</code>-method instead of having the dedicated <code class="notranslate">Note#comments_with_extra_open_comment</code>-method?</p>
<p dir="auto">I tried this out but realised quickly some issues with this:<br>
a) We have calls to <code class="notranslate">Note#comments</code> from the (Web) NotesController context, which expects no prepended <code class="notranslate">open</code>-comment.</p>
<p dir="auto">b) <code class="notranslate">Note#comments</code> returns an Active Record Collection Proxy-object. Overriding the <code class="notranslate">Note#comments</code>-behaviour so that it occasionally returns an Array instead, may lead to weird bugs. E.g. calls like <code class="notranslate">note.comments.create</code> will fail with a <code class="notranslate">NoMethodError</code>.</p>
<blockquote>
<p dir="auto">Does it leak abstractions too much?</p>
</blockquote>
<p dir="auto">I am not sure what you mean with that. The idea of <code class="notranslate">Note#comments_with_extra_open_comment</code> is to hide the logic inside the model and make it obvious to developers that this method returns something special.</p>
<p dir="auto">I've now added a <code class="notranslate">Note#api_comments</code>-method which should always return the full list of note comments including the <code class="notranslate">open</code>-comment.</p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4481#discussion_r1768000518">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLMJYFHVJK3EA5EWX3TZX767LAVCNFSM6AAAAABB4FLGOWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGMJXGI4TENZQHA">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLOBAUSSUVLCONKSPJ3ZX767LA5CNFSM6AAAAABB4FLGOWWGG33NNVSW45C7OR4XAZNRKB2WY3CSMVYXKZLTORJGK5TJMV32UY3PNVWWK3TUL5UWJTUKD4KKI.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/4481/review/2317292708</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/4481#discussion_r1768000518",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/4481#discussion_r1768000518",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>