<li>I finally got around to working on Peter’s cleanups for affiliations, authors, and donors from last week
<ul>
<li>I did some minor cleanups myself and applied them to CGSpace</li>
</ul>
</li>
<li>Start working on some batch uploads for IFPRI</li>
</ul>
<h2id="2023-08-04">2023-08-04</h2>
<ul>
<li>Minor cleanups on IFPRI’s batch uploads
<ul>
<li>I also did a duplicate check and found thirteen items that seem to be duplicates, so I sent them to Leigh to check</li>
</ul>
</li>
<li>I read this <ahref="https://www.endpointdev.com/blog/2012/06/logstatement-postgres-all-full-logging/">interesting blog post about PostgreSQL’s <code>log_statement</code> function</a>
<ul>
<li>Someone pointed out that this also lets you take advantage of <ahref="https://github.com/darold/pgbadger">PgBadger</a> analysis</li>
<li>I enabled statement logging on DSpace Test and I will check it in a few days</li>
</ul>
</li>
<li>Reading about DSpace 7 REST API again
<ul>
<li>Here is how to get the first page of 100 items: <ahref="https://dspace7test.ilri.org/server/api/discover/search/objects?dsoType=item&page=1&size=100">https://dspace7test.ilri.org/server/api/discover/search/objects?dsoType=item&page=1&size=100</a></li>
<li>I really want to benchmark this to see how fast we can get all the pages</li>
<li>Another thing I notice is that the bitstreams are not here, so that will be an extra call…</li>
<li>I’m checking the PostgreSQL logs now that statement logging has been enabled for a few days on DSpace Test
<ul>
<li>I see the logs are about 7 or 8 GB, which is larger than expected—and this is the test server!</li>
<li>I will now play with pgbadger to see if it gives any useful insights</li>
<li>Hmm, it sems the <code>log_statement</code> advice was old as pgbadger itself says:</li>
</ul>
</li>
</ul>
<blockquote>
<p>Do not enable log_statement as its log format will not be parsed by pgBadger.</p>
</blockquote>
<p>… and:</p>
<blockquote>
<p>Warning: Do not enable both log_min_duration_statement, log_duration and log_statement all together, this will result in wrong counter values. Note that this will also increase drastically the size of your log. log_min_duration_statement should always be preferred.</p>
</blockquote>
<ul>
<li>So we need to follow pgbadger’s instructions rather to get a suitable log file
<ul>
<li>After enabling the new settings I see that our log file is going to be reaallllly big… hmmmm will check tomorrow morning</li>
<li>Ideally we would run this incremental report every day on the postgresql-14-main.log.1 aka yesterday’s version of the log file after it is rotated
<ul>
<li>Now I have to see how large the file will be…</li>
</ul>
</li>
<li>I did some final updates to the ninety IFPRI records and uploaded them to DSpace Test first, then to CGSpace</li>
<li>I noticed that the DSpace statistics pages don’t seem to work on communities or collections
<ul>
<li>I finally took time to look in the DSpace log file and found this for one:</li>
</ul>
</li>
</ul>
<divclass="highlight"><pretabindex="0"style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><codeclass="language-console"data-lang="console"><spanstyle="display:flex;"><span>2023-08-16 14:30:31,873 WARN dace8f96-f034-488e-b38c-9f2eb5d0e002 6cbd0b18-6852-4294-99a5-02dfcab0a469 org.dspace.app.rest.exception.DSpaceApiExceptionControllerAdvice @ Request is invalid or incorrect (status:400 exception: Invalid UUID string: -1 at: java.base/java.util.UUID.fromString1(UUID.java:280))
</span></span></code></pre></div><ul>
<li>I’m surprised to see this because those should have been dealt with when we upgraded to DSpace 6
<ul>
<li>Looking in the Solr statistics core I see ~1,000,000 documents with the ID <code>-1</code>, and about 57,000,000 that don’t</li>
<li>Also interesting, faceting by <code>dateYear</code> I see:
<ul>
<li>2023: 209566</li>
<li>2022: 403871</li>
<li>2021: 336548</li>
<li>2020: 31659</li>
<li>… none before 2020</li>
</ul>
</li>
<li>They are all type 5, which is “Site” aka the home page, according to <code>dspace-api/src/main/java/org/dspace/core/Constants.java</code></li>
<li>Ah hah, and I can see in my DSpace 7 test Solr there are a bunch of hits with <code>type: 5</code> that have “-1” of course, but also newer ones that have an actual UUID</li>
<li>I used the <code>/server/api/dso/find?uuid=3945ec23-2426-4fce-a2ea-48b38b91547f</code> endpoint to find out that there is a new <code>/server/api/core/sites</code> endpoint listing exactly one site (the home page) with this ID</li>
<li>So for now I can replace all the “-1” documents with this ID on the test server at least, then I will have to remember to do that during the migration of the production instance</li>
<li>I did a new export from DSpace 6 using solr-import-export-json with a query limiting it to documents of type 5 and negative 1 ID:</li>
</ul>
</li>
</ul>
<divclass="highlight"><pretabindex="0"style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><codeclass="language-console"data-lang="console"><spanstyle="display:flex;"><span>$ chrt -b <spanstyle="color:#ae81ff">0</span> ./run.sh -s http://localhost:8081/solr/statistics -a export -o /tmp/statistics-fix-uuid.json -f <spanstyle="color:#e6db74">'id:\-1 AND type:5 AND time:[2020-01-01T00\:00\:00Z TO 2023-12-31T23\:59\:59Z]'</span> -k uid -S actingGroupId,actingGroupParentId,actorMemberGroupId,author_mtdt,author_mtdt_search,bitstreamCount,bitstreamId,complete_query,complete_query_search,containerBitstream,containerCollection,containerCommunity,containerItem,core_update_run_nb,countryCode_ngram,countryCode_search,cua_version,dateYear,dateYearMonth,file_id,filterquery,first_name,geoipcountrycode,geoIpCountryCode,group_id,group_map,group_name,ip_ngram,ip_search,isArchived,isInternal,iso_mtdt,iso_mtdt_search,isWithdrawn,last_name,name,ngram_query_search,ngram_simplequery_search,orphaned,parent_count,p_communities_id,p_communities_map,p_communities_name,p_group_id,p_group_map,p_group_name,range,rangeDescription,rangeDescription_ngram,rangeDescription_search,range_ngram,range_search,referrer_ngram,referrer_search,simple_query,simple_query_search,solr_update_time_stamp,storage_nb_of_bitstreams,storage_size,storage_statistics_type,subject_mtdt,subject_mtdt_search,text,userAgent_ngram,userAgent_search,version_id,workflowItemId
</span></span></code></pre></div><ul>
<li>Then I replaced the IDs with the UUID of the site homepage on DSpace 7 Test:</li>
</ul>
<divclass="highlight"><pretabindex="0"style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><codeclass="language-console"data-lang="console"><spanstyle="display:flex;"><span>$ sed -i <spanstyle="color:#e6db74">'s/"id":"-1"/"id":"3945ec23-2426-4fce-a2ea-48b38b91547f"/'</span> /tmp/statistics-fix-uuid.json
</span></span></code></pre></div><ul>
<li>I re-imported those records and I no longer see the “-1” IDs, but still get the same error in the log
<ul>
<li>I don’t understand, maybe there is some voodoo, so I rebooted the server</li>
<li>Hmm, no, it’s not a voodoo cache issue, so I really need to debug this:</li>
</ul>
</li>
</ul>
<divclass="highlight"><pretabindex="0"style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><codeclass="language-console"data-lang="console"><spanstyle="display:flex;"><span>2023-08-16 15:44:07,122 WARN dace8f96-f034-488e-b38c-9f2eb5d0e002 036b88e6-7548-4852-9646-f345ce3bfcc2 org.dspace.app.rest.exception.DSpaceApiExceptionControllerAdvice @ Request is invalid or incorrect (status:400 exception: Invalid UUID string: -1 at: java.base/java.util.UUID.fromString1(UUID.java:280))
</span></span></code></pre></div><ul>
<li>On a related note, I figured out that the root site already has a UUID in DSpace 6, and it’s exactly the one above (3945ec23-2426-4fce-a2ea-48b38b91547f)
<ul>
<li>I noticed it while looking at the <ahref="https://cgspace.cgiar.org/rest/hierarchy">DSpace 6 REST API’s hierarchy page</a></li>
<li>So I can update these “-1” IDs with “type:5” in our production I think…</li>
</ul>
</li>
</ul>
<h2id="2023-08-17">2023-08-17</h2>
<ul>
<li>I decided to update the “-1” IDs in Solr on DSpace 6
<ul>
<li>Unfortunately, in Solr there is no way to update only documents matching a query, so we have to export and re-import</li>
<li>I exported all documents with “type:5” (Homepage) and replaced the ID in the JSON:</li>
</span></span><spanstyle="display:flex;"><span>$ sed -i <spanstyle="color:#e6db74">'s/"id":"-1"/"id":"3945ec23-2426-4fce-a2ea-48b38b91547f"/'</span> /tmp/statistics-fix-uuid.json
</span></span></code></pre></div><ul>
<li>(Oops, skipping the fields above was not necessary, since I’m importing back into DSpace 6 where those fields exist)</li>
<li>Then I re-imported:</li>
</ul>
<pretabindex="0"><code>$ ./run.sh -s http://localhost:8081/solr/statistics -a import -o /tmp/statistics-fix-uuid.json -k uid
</code></pre><ul>
<li>This worked, but I still see new records coming in that have “id:-1” so I will need to repeat this during the migration.</li>
<li>I also notice many stats records that have erroneous cities:
<li>I wrote a Python script to benchmark harvesting all 100,000+ items using the <code>/api/discover/search/objects</code> endpoint 100 items at a time</li>
<li>I was able to harvest the entire 106,000 items in fifty-two minutes, which seems slow, but that’s about ten times faster than with the legacy REST API…</li>
<li>Still, I need to benchmark a bit more, as the item response doesn’t include collection mappings or thumbnails</li>
</ul>
</li>
<li>Reading the <ahref="https://github.com/DSpace/RestContract/blob/main/README.md#etags--conditional-headers">API docs</a> it seems that we should be able to use the standard <code>If-Modified-Since</code> header for some endpoints
<ul>
<li>I tried it on the <code>/api/discover/search/objects</code> and <code>/api/core/items</code> endpoints, but apparently those don’t support this header because I don’t see a <code>Last-Modified</code> header in the response</li>
<li>According to the docs, it means that these endpoints indeed don’t support it…</li>
</ul>
</li>
</ul>
<h2id="2023-08-22">2023-08-22</h2>
<ul>
<li>I was experimenting with the DSpace 7 REST API again
<ul>
<li>This time looking at the thumbnail responses in item endpoints</li>
<li>According to <ahref="https://github.com/DSpace/RestContract/blob/main/items.md#main-thumbnail">the documentation</a> the API will respond with HTTP 200 if there is a thumbnail, and HTTP 204 if there is no content</li>
<li>That means we need to make the request before we can even find out!</li>
<li>Tim on DSpace Slack pointed out the DSpace 7 REST API’s <ahref="https://github.com/DSpace/RestContract/blob/main/projections.md">projections</a>
<ul>
<li>This means we can embed resources like thumbnail and owningCollection in the item (and other) requests, for example: <ahref="https://dspace7test.ilri.org/server/api/discover/search/objects?dsoType=item&embed=thumbnail,owningCollection">https://dspace7test.ilri.org/server/api/discover/search/objects?dsoType=item&embed=thumbnail,owningCollection</a></li>
</ul>
</li>
</ul>
<h2id="2023-08-23">2023-08-23</h2>
<ul>
<li>I benchmarked the DSpace 7 REST API with the new embeds and it took four hours and seventeen minutes to get all 106,000 items on DSpace 7 Test
<ul>
<li>So this is much slower than the results I saw earlier this week, but maybe slightly faster than DSpace 6?</li>
</ul>
</li>
<li>Maria from Alliance contacted me to say they have agreed to use UN M.49 regions more strictly in TIP, so they want to replace our non-standard “Latin America” region with “Latin America and the Caribbean”, “Caribbean” and “Americas” on all Alliance outputs
<ul>
<li>I exported their community on CGSpace and fixed the metadata in OpenRefine</li>
</ul>
</li>
<li>I tried to run <code>dspace cleanup -v</code> on CGSpace, but got this error:</li>
</ul>
<pretabindex="0"><code>Caused by: org.postgresql.util.PSQLException: ERROR: update or delete on table "bitstream" violates foreign key constraint "bundle_primary_bitstream_id_fkey" on table "bundle"
Detail: Key (uuid)=(61bff7da-c8e3-420f-841c-ec5e8238d716) is still referenced from table "bundle".
</code></pre><ul>
<li>The solution, as always, is to delete those IDs manually in PostgreSQL:</li>
</ul>
<pretabindex="0"><code>$ psql -d dspace -c "UPDATE bundle SET primary_bitstream_id=NULL WHERE primary_bitstream_id IN ('61bff7da-c8e3-420f-841c-ec5e8238d716');"
UPDATE 1
</code></pre><ul>
<li>I also tried to delete all users who haven’t logged in since 2017 using the groomer script, but it crashes due to those users still having items or workflows or whatever:</li>
</ul>
<divclass="highlight"><pretabindex="0"style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><codeclass="language-console"data-lang="console"><spanstyle="display:flex;"><span>$ dspace dsrun org.dspace.eperson.Groomer -a -b 08/23/2017 -d
</span></span></code></pre></div><ul>
<li>I see that it is now <ahref="https://github.com/DSpace/DSpace/pull/2229">possible in DSpace 7 to delete such users</a> so we will have to wait</li>
<li>A few weeks ago we received a request from the Fruits and Vegetables Initiative saying that they’ve gotten approval to begin using the long name instead of the short one everywhere, apparently for SEO reasons
<ul>
<li>After communicating with PRMS and other teams working on systems using this metadata I finally updated them in CGSpace</li>
</ul>
</li>
<li>Export CGSpace to check for missing Initiative collection mappings</li>