<p>After a bit more testing... Once gem "activerecord-import" gets added to the Gemfile,<code>trace.rb</code> <code>import</code> method could be enhanced to use bulk inserts via the following code. I also added the <code>tile</code> field, which wasn't included in the original source yet. If I'm not missing anything, this should really be all. SELECT for validation purposes also won't show up in the trace.</p>
<div class="highlight highlight-source-ruby"><pre> <span class="pl-c"><span class="pl-c">#</span> If there are any existing points for this trace then delete them</span>
<span class="pl-c1">Tracepoint</span>.where(<span class="pl-c1">:gpx_id</span> => id).delete_all
tps <span class="pl-k">=</span> []
gpx.points <span class="pl-k">do</span> |<span class="pl-smi">point</span>|
<span class="pl-k">if</span> first
f_lat <span class="pl-k">=</span> point.latitude
f_lon <span class="pl-k">=</span> point.longitude
first <span class="pl-k">=</span> <span class="pl-c1">false</span>
<span class="pl-k">end</span>
tp <span class="pl-k">=</span> <span class="pl-c1">Tracepoint</span>.<span class="pl-k">new</span>
tp.lat <span class="pl-k">=</span> point.latitude
tp.lon <span class="pl-k">=</span> point.longitude
tp.altitude <span class="pl-k">=</span> point.altitude
tp.timestamp <span class="pl-k">=</span> point.timestamp
tp.gpx_id <span class="pl-k">=</span> id
tp.tile <span class="pl-k">=</span> <span class="pl-c1">QuadTile</span>.tile_for_point(point.latitude, point.longitude)
tp.trackid <span class="pl-k">=</span> point.segment
tps <span class="pl-k"><<</span> tp
<span class="pl-k">end</span>
<span class="pl-c1">Tracepoint</span>.import tps, <span class="pl-c1">:validate</span> => <span class="pl-c1">false</span></pre></div>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/issues/1852#issuecomment-427110022">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABWnLY9j_TE2i9S84anf_SxSqhRi93-bks5uhkoWgaJpZM4T3-LP">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABWnLaBZ2NPCUom6SzWd_Ye9wJiBWmEbks5uhkoWgaJpZM4T3-LP.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/openstreetmap/openstreetmap-website","title":"openstreetmap/openstreetmap-website","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/openstreetmap/openstreetmap-website"}},"updates":{"snippets":[{"icon":"PERSON","message":"@mmd-osm in #1852: After a bit more testing... Once gem \"activerecord-import\" gets added to the Gemfile,` trace.rb` `import` method could be enhanced to use bulk inserts via the following code. I also added the `tile` field, which wasn't included in the original source yet. If I'm not missing anything, this should really be all. SELECT for validation purposes also won't show up in the trace.\r\n\r\n```ruby\r\n # If there are any existing points for this trace then delete them\r\n Tracepoint.where(:gpx_id =\u003e id).delete_all\r\n\r\n tps = []\r\n gpx.points do |point|\r\n if first\r\n f_lat = point.latitude\r\n f_lon = point.longitude\r\n first = false\r\n end\r\n\r\n tp = Tracepoint.new\r\n tp.lat = point.latitude\r\n tp.lon = point.longitude\r\n tp.altitude = point.altitude\r\n tp.timestamp = point.timestamp\r\n tp.gpx_id = id\r\n tp.tile = QuadTile.tile_for_point(point.latitude, point.longitude)\r\n tp.trackid = point.segment\r\n tps \u003c\u003c tp\r\n end\r\n \r\n Tracepoint.import tps, :validate =\u003e false\r\n```"}],"action":{"name":"View Issue","url":"https://github.com/openstreetmap/openstreetmap-website/issues/1852#issuecomment-427110022"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/issues/1852#issuecomment-427110022",
"url": "https://github.com/openstreetmap/openstreetmap-website/issues/1852#issuecomment-427110022",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [openstreetmap/openstreetmap-website] Integrate the high-performance GPX importer (#1852)",
"sections": [
{
"text": "",
"activityTitle": "**mmd**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@mmd-osm",
"facts": [
]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"openstreetmap/openstreetmap-website\",\n\"issueId\": 1852,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"name": "Close issue",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueClose\",\n\"repositoryFullName\": \"openstreetmap/openstreetmap-website\",\n\"issueId\": 1852\n}"
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/openstreetmap/openstreetmap-website/issues/1852#issuecomment-427110022"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 333439695\n}"
}
],
"themeColor": "26292E"
}
]</script>