<commit_before>ALTER TABLE movies ADD COLUMN parent_id INT;
ALTER TABLE movies ADD COLUMN movie_sort_value INT8;
UPDATE movies SET parent_id = t.parent_id 
       FROM 
       (SELECT m.id AS parent_id,e.id AS episode_id FROM movies m
        INNER JOIN movies e ON e.episode_parent_title = m.full_title) t
       WHERE id = t.episode_id;

CREATE OR REPLACE FUNCTION first_release_stamp(movie_id INT)
RETURNS INT8
AS
$$
SELECT EXTRACT(epoch FROM MIN(release_stamp))::INT8 FROM release_dates WHERE movie_id = $1
$$
LANGUAGE SQL;

UPDATE movies SET movie_sort_value = first_release_stamp(id);

CREATE INDEX movies_idx_parent_id ON movies (parent_id);
<commit_msg>Better way of filling movie_sort_value. Much faster too<commit_after>ALTER TABLE movies ADD COLUMN parent_id INT;
ALTER TABLE movies ADD COLUMN movie_sort_value INT8;
UPDATE movies SET parent_id = t.parent_id 
       FROM 
       (SELECT m.id AS parent_id,e.id AS episode_id FROM movies m
        INNER JOIN movies e ON e.episode_parent_title = m.full_title) t
       WHERE id = t.episode_id;

UPDATE movies m SET movie_sort_value = rd.stamp
       FROM (SELECT movie_id,EXTRACT(epoch FROM MIN(release_stamp)) AS stamp
                    FROM release_dates
                    GROUP BY movie_id) rd
       WHERE m.id = rd.movie_id;

CREATE INDEX movies_idx_parent_id ON movies (parent_id);

{'fraction_non_alphanumeric': 0.05547337278106509, 'fraction_numerical': 0.0036982248520710057, 'mean_word_length': 3.570945945945946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3493000', 'n_tokens_mistral': 449, 'n_tokens_neox': 434, 'n_words': 146}