<commit_before>CREATE OR REPLACE FUNCTION maybe_file(
    fpath text,
    repo_id integer
) RETURNS integer AS $$
DECLARE
    fid integer;
BEGIN
    -- Now for the fun part, to share knowledge with other developers
    IF EXISTS(SELECT id FROM files
        WHERE repo = repo_id
        AND name = fpath)
    THEN
        SELECT id INTO fid FROM files
        WHERE repo = repo_id
        AND name = fpath;
        RETURN fid;
    ELSE
        INSERT INTO files (repo, name) VALUES (
            repo_id,
            fpath
        ) RETURNING id INTO fid;
    END IF;
    RETURN fid;
END;

$$ LANGUAGE plpgsql;<commit_msg>improve performance of file_id function<commit_after>CREATE OR REPLACE FUNCTION maybe_file(
    fpath text,
    repo_id integer
) RETURNS integer AS $$
DECLARE
    fid integer;
BEGIN
    -- either creates a file or returns the existing ID
    INSERT INTO files (repo, name) (
    SELECT repo_id AS repo, fpath AS name
        WHERE NOT EXISTS (
            SELECT 1 FROM files
                WHERE repo = repo_id AND name = fpath
            )
    ) RETURNING id INTO fid;
    return fid;
END;

$$ LANGUAGE plpgsql;
{'fraction_non_alphanumeric': 0.05272407732864675, 'fraction_numerical': 0.0008787346221441124, 'mean_word_length': 2.1205479452054794, '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': '6876831', 'n_tokens_mistral': 358, 'n_tokens_neox': 339, 'n_words': 135}