Page MenuHomeSoftware Heritage
Paste P190

Bulking directory listings with swh_directory_walk_many
ActivePublic

Authored by seirl on Nov 9 2017, 2:48 PM.
create or replace function swh_directory_walk_many(walked_dirs_id bytea[])
returns setof directory_entry
language sql
stable
as $$
with dir as (
select id as dir_id, dir_entries, file_entries, rev_entries
from directory
where ARRAY[CAST (id AS bytea)] <@ walked_dirs_id),
ls_d as (select dir_id, unnest(dir_entries) as entry_id from dir),
ls_f as (select dir_id, unnest(file_entries) as entry_id from dir),
ls_r as (select dir_id, unnest(rev_entries) as entry_id from dir)
(select dir_id, 'dir'::directory_entry_type as type,
e.target, e.name, e.perms, NULL::content_status,
NULL::sha1, NULL::sha1_git, NULL::sha256, NULL::bigint
from ls_d
left join directory_entry_dir e on ls_d.entry_id = e.id)
union
(select dir_id, 'file'::directory_entry_type as type,
e.target, e.name, e.perms, c.status,
c.sha1, c.sha1_git, c.sha256, c.length
from ls_f
left join directory_entry_file e on ls_f.entry_id = e.id
left join content c on e.target = c.sha1_git)
union
(select dir_id, 'rev'::directory_entry_type as type,
e.target, e.name, e.perms, NULL::content_status,
NULL::sha1, NULL::sha1_git, NULL::sha256, NULL::bigint
from ls_r
left join directory_entry_rev e on ls_r.entry_id = e.id)
order by name;
$$;

Event Timeline

Diff from walk_one:

diff --git a/walk_one b/walk_many
index 69aa56e..7a813df 100644
--- a/walk_one
+++ b/walk_many
@@ -1,4 +1,4 @@
-create or replace function swh_directory_walk_one(walked_dir_id sha1_git)
+create or replace function swh_directory_walk_many(walked_dirs_id bytea[])
     returns setof directory_entry
     language sql
     stable
@@ -6,7 +6,7 @@ as $$
     with dir as (
     select id as dir_id, dir_entries, file_entries, rev_entries
     from directory
-    where id = walked_dir_id),
+    where ARRAY[CAST (id AS bytea)] <@ walked_dirs_id),
     ls_d as (select dir_id, unnest(dir_entries) as entry_id from dir),
     ls_f as (select dir_id, unnest(file_entries) as entry_id from dir),
     ls_r as (select dir_id, unnest(rev_entries) as entry_id from dir)