This Week I Learned: 2020-12-13

  1. If you’re doing a query with a subselect on the @rid field in OrientDB, you need to filter out nulls from your subselect or you’ll get a OSBTreeException saying “Null keys are not supported”. It wouldn’t be a Java program without the odd glorified NullPointerException, I guess.
  2. How to set up a slow query log in MongoDB. And that when you add the vital missing index, this operation too will slow up in the slow query log.
  3. PHP arrays are slightly faster than objects, but they actually use a boatload more memory. And did you know that if you have a numerically-indexed array with the last key being n, and then you unset($myArray['n']), the next value pushed to the array will have key n+1 and your array will now be associative? Just two weird PHP array facts from Larry Garfield’s great Nomad PHP talk about why most uses of arrays in PHP should be replaced by custom classes which can provide better type safety and readability.
  4. Composer 2.0 is now released and it’s way faster. I’m looking forward to having my first play with it over the Christmas break.
  5. Why some old-school HTML format-related tags (e.g. <b> and <i>) aren’t deprecated when most of the others are (e.g. <font> and <strike>). The purist in me thinks that if these tags have really come to have a meaning beyond just the formatting, they could be renamed to something that conveys that more clearly – it would never occur to me that <u> is for annotating spelling errors!

This Week I Learned: 2020-12-06

  1. When it’s used as a pipeline within a $lookup, MongoDB’s $expr operator only supports indexes for equality matches. $in is apparently not considered an equality match, even when the search array only holds one value and in other situations the query parser would treat it as an $eq.
  2. MongoDB supports wildcard indexes to quickly define an index for all fields in a document or subdocument.
  3. Some more useful applications of JavaScript’s Array.reduce() function, beyond summing numbers. I do miss some of the array utility functions from underscore/lodash when I’m working in projects that don’t use them, but it had never occurred to me to try to recreate them like this.
  4. I enjoyed these tips for front-end security and learned a few things (particularly some new HTTP headers such as Content-Security-Policy and X-Frame-Options). I don’t agree that front ends should be sanitising input against SQL injection attacks, though – that is definitely a job for the back end since attackers could bypass the front end altogether and send their malicious content straight to the server, and doing it twice introduces the risk of unwanted double-escaping.
  5. There’s a new media query in town and it’s called prefers-reduced-data. There’s also an HTTP header called Saves-Data, and both are intended to indicate to an application that it should be more conservative with how much data they send to the user. I can see applications for this on the front end (polling the server for updates less frequently, for instance) and the back end (sending fewer fields for each record, or reducing the pagination size), and as a data miser myself I’ll be very interested to see if it achieves widespread support.