simonw / git-history

Tools for analyzing Git history using SQLite
Apache License 2.0
191 stars 18 forks source link

Better `item_version_detail` view #37

Closed simonw closed 2 years ago

simonw commented 2 years ago

Including the list of columns is useful:

select
  commits.commit_at as _commit_at,
  commits.hash as _commit_hash,
  item_version.*,
  (
    select json_group_array(name) from columns
    where id in (
      select column from item_changed
      where item_version = item_version._id
    )
  ) as changed_columns
from
  item_version
  join commits on commits.id = item_version._commit
  join item_changed on item_version._id = item_changed.item_version

I tried this with a join and group by instead of that nested select json_group_array but the performance was terrible, presumably because it has to calculate for every single row as opposed to the subset of rows returned on the page.

simonw commented 2 years ago

Bug in this: the unnecessary join against item_changed on the last line causes multiple rows to be returned for each item version.