Add notes for 2018-09-24

This commit is contained in:
Alan Orth 2018-09-24 13:40:59 +03:00
parent cb043e63dd
commit 1814a1f064
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9
3 changed files with 72 additions and 8 deletions

View File

@ -401,4 +401,34 @@ dspace=# select item_id from item where in_archive is True and withdrawn is Fals
- Also, I need to test the new LDAP server, so I will deploy that on DSpace Test today - Also, I need to test the new LDAP server, so I will deploy that on DSpace Test today
- Rename my cgspace-statistics-api to [dspace-statistics-api](https://github.com/alanorth/dspace-statistics-api) on GitHub - Rename my cgspace-statistics-api to [dspace-statistics-api](https://github.com/alanorth/dspace-statistics-api) on GitHub
## 2018-09-24
- Trying to figure out how to get item views and downloads from SQLite in a join
- It appears SQLite doesn't support `FULL OUTER JOIN` so some people on StackOverflow have emulated it with `LEFT JOIN` and `UNION`:
```
> SELECT views.views, views.id, downloads.downloads, downloads.id FROM itemviews views
LEFT JOIN itemdownloads downloads USING(id)
UNION ALL
SELECT views.views, views.id, downloads.downloads, downloads.id FROM itemdownloads downloads
LEFT JOIN itemviews views USING(id)
WHERE views.id IS NULL;
```
- This "works" but the resulting rows are kinda messy so I'd have to do extra logic in Python
- Maybe we can use one "items" table with defaults values and UPSERT (aka insert... on conflict ... do update):
```
sqlite> CREATE TABLE items(id INT PRIMARY KEY, views INT DEFAULT 0, downloads INT DEFAULT 0);
sqlite> INSERT INTO items(id, views) VALUES(0, 52);
sqlite> INSERT INTO items(id, downloads) VALUES(1, 171);
sqlite> INSERT INTO items(id, downloads) VALUES(1, 176) ON CONFLICT(id) DO UPDATE SET downloads=176;
sqlite> INSERT INTO items(id, views) VALUES(0, 78) ON CONFLICT(id) DO UPDATE SET views=78;
sqlite> INSERT INTO items(id, views) VALUES(0, 3) ON CONFLICT(id) DO UPDATE SET downloads=3;
sqlite> INSERT INTO items(id, views) VALUES(0, 7) ON CONFLICT(id) DO UPDATE SET downloads=excluded.views;
```
- This totally works!
- Note the special `excluded.views` form! See [SQLite's lang_UPSERT documentation](https://www.sqlite.org/lang_UPSERT.html)
<!-- vim: set sw=2 ts=2: --> <!-- vim: set sw=2 ts=2: -->

View File

@ -18,7 +18,7 @@ I&rsquo;m testing the new DSpace 5.8 branch in my Ubuntu 18.04 environment and I
" /> " />
<meta property="og:type" content="article" /> <meta property="og:type" content="article" />
<meta property="og:url" content="https://alanorth.github.io/cgspace-notes/2018-09/" /><meta property="article:published_time" content="2018-09-02T09:55:54&#43;03:00"/> <meta property="og:url" content="https://alanorth.github.io/cgspace-notes/2018-09/" /><meta property="article:published_time" content="2018-09-02T09:55:54&#43;03:00"/>
<meta property="article:modified_time" content="2018-09-23T16:51:17&#43;03:00"/> <meta property="article:modified_time" content="2018-09-24T00:31:59&#43;03:00"/>
<meta name="twitter:card" content="summary"/> <meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="September, 2018"/> <meta name="twitter:title" content="September, 2018"/>
<meta name="twitter:description" content="2018-09-02 <meta name="twitter:description" content="2018-09-02
@ -41,9 +41,9 @@ I&rsquo;m testing the new DSpace 5.8 branch in my Ubuntu 18.04 environment and I
"@type": "BlogPosting", "@type": "BlogPosting",
"headline": "September, 2018", "headline": "September, 2018",
"url": "https://alanorth.github.io/cgspace-notes/2018-09/", "url": "https://alanorth.github.io/cgspace-notes/2018-09/",
"wordCount": "2893", "wordCount": "3094",
"datePublished": "2018-09-02T09:55:54&#43;03:00", "datePublished": "2018-09-02T09:55:54&#43;03:00",
"dateModified": "2018-09-23T16:51:17&#43;03:00", "dateModified": "2018-09-24T00:31:59&#43;03:00",
"author": { "author": {
"@type": "Person", "@type": "Person",
"name": "Alan Orth" "name": "Alan Orth"
@ -576,6 +576,40 @@ $ grep -c -E 'session_id=[A-Z0-9]{32}:ip_addr=50.116.102.77' dspace.log.2018-09-
<li>Rename my cgspace-statistics-api to <a href="https://github.com/alanorth/dspace-statistics-api">dspace-statistics-api</a> on GitHub</li> <li>Rename my cgspace-statistics-api to <a href="https://github.com/alanorth/dspace-statistics-api">dspace-statistics-api</a> on GitHub</li>
</ul> </ul>
<h2 id="2018-09-24">2018-09-24</h2>
<ul>
<li>Trying to figure out how to get item views and downloads from SQLite in a join</li>
<li>It appears SQLite doesn&rsquo;t support <code>FULL OUTER JOIN</code> so some people on StackOverflow have emulated it with <code>LEFT JOIN</code> and <code>UNION</code>:</li>
</ul>
<pre><code>&gt; SELECT views.views, views.id, downloads.downloads, downloads.id FROM itemviews views
LEFT JOIN itemdownloads downloads USING(id)
UNION ALL
SELECT views.views, views.id, downloads.downloads, downloads.id FROM itemdownloads downloads
LEFT JOIN itemviews views USING(id)
WHERE views.id IS NULL;
</code></pre>
<ul>
<li>This &ldquo;works&rdquo; but the resulting rows are kinda messy so I&rsquo;d have to do extra logic in Python</li>
<li>Maybe we can use one &ldquo;items&rdquo; table with defaults values and UPSERT (aka insert&hellip; on conflict &hellip; do update):</li>
</ul>
<pre><code>sqlite&gt; CREATE TABLE items(id INT PRIMARY KEY, views INT DEFAULT 0, downloads INT DEFAULT 0);
sqlite&gt; INSERT INTO items(id, views) VALUES(0, 52);
sqlite&gt; INSERT INTO items(id, downloads) VALUES(1, 171);
sqlite&gt; INSERT INTO items(id, downloads) VALUES(1, 176) ON CONFLICT(id) DO UPDATE SET downloads=176;
sqlite&gt; INSERT INTO items(id, views) VALUES(0, 78) ON CONFLICT(id) DO UPDATE SET views=78;
sqlite&gt; INSERT INTO items(id, views) VALUES(0, 3) ON CONFLICT(id) DO UPDATE SET downloads=3;
sqlite&gt; INSERT INTO items(id, views) VALUES(0, 7) ON CONFLICT(id) DO UPDATE SET downloads=excluded.views;
</code></pre>
<ul>
<li>This totally works!</li>
<li>Note the special <code>excluded.views</code> form! See <a href="https://www.sqlite.org/lang_UPSERT.html">SQLite&rsquo;s lang_UPSERT documentation</a></li>
</ul>
<!-- vim: set sw=2 ts=2: --> <!-- vim: set sw=2 ts=2: -->

View File

@ -4,7 +4,7 @@
<url> <url>
<loc>https://alanorth.github.io/cgspace-notes/2018-09/</loc> <loc>https://alanorth.github.io/cgspace-notes/2018-09/</loc>
<lastmod>2018-09-23T16:51:17+03:00</lastmod> <lastmod>2018-09-24T00:31:59+03:00</lastmod>
</url> </url>
<url> <url>
@ -184,7 +184,7 @@
<url> <url>
<loc>https://alanorth.github.io/cgspace-notes/</loc> <loc>https://alanorth.github.io/cgspace-notes/</loc>
<lastmod>2018-09-23T16:51:17+03:00</lastmod> <lastmod>2018-09-24T00:31:59+03:00</lastmod>
<priority>0</priority> <priority>0</priority>
</url> </url>
@ -195,7 +195,7 @@
<url> <url>
<loc>https://alanorth.github.io/cgspace-notes/tags/notes/</loc> <loc>https://alanorth.github.io/cgspace-notes/tags/notes/</loc>
<lastmod>2018-09-23T16:51:17+03:00</lastmod> <lastmod>2018-09-24T00:31:59+03:00</lastmod>
<priority>0</priority> <priority>0</priority>
</url> </url>
@ -207,13 +207,13 @@
<url> <url>
<loc>https://alanorth.github.io/cgspace-notes/posts/</loc> <loc>https://alanorth.github.io/cgspace-notes/posts/</loc>
<lastmod>2018-09-23T16:51:17+03:00</lastmod> <lastmod>2018-09-24T00:31:59+03:00</lastmod>
<priority>0</priority> <priority>0</priority>
</url> </url>
<url> <url>
<loc>https://alanorth.github.io/cgspace-notes/tags/</loc> <loc>https://alanorth.github.io/cgspace-notes/tags/</loc>
<lastmod>2018-09-23T16:51:17+03:00</lastmod> <lastmod>2018-09-24T00:31:59+03:00</lastmod>
<priority>0</priority> <priority>0</priority>
</url> </url>