Skip to content
Snippets Groups Projects
Commit 2a9e8b90 authored by Stefano Zacchiroli's avatar Stefano Zacchiroli
Browse files

swh_content_find_dir: port to merged dir entries

parent 69d3ea78
No related branches found
No related tags found
No related merge requests found
......@@ -583,8 +583,7 @@ begin
(select dir.id as dir_id, dir_entry_f.name as name, 0 as depth
from directory_entry_file as dir_entry_f
join content on content.sha1_git = dir_entry_f.target
join directory_list_file as ls_f on ls_f.entry_ids @> array[dir_entry_f.id]
join directory as dir on ls_f.dir_id = dir.id
join directory as dir on dir.file_entries @> array[dir_entry_f.id]
where content.sha1 = content_id
limit 1)
union all
......@@ -593,8 +592,7 @@ begin
path.depth + 1
from path
join directory_entry_dir as dir_entry_d on dir_entry_d.target = path.dir_id
join directory_list_dir as ls_d on ls_d.entry_ids @> array[dir_entry_d.id]
join directory as dir on ls_d.dir_id = dir.id
join directory as dir on dir.dir_entries @> array[dir_entry_d.id]
limit 1)
)
select dir_id, name from path order by depth desc limit 1
......
......@@ -34,3 +34,33 @@ create index on directory using gin (rev_entries);
drop table directory_list_dir;
drop table directory_list_file;
drop table directory_list_rev;
create or replace function swh_content_find_directory(content_id sha1)
returns content_dir
language plpgsql
as $$
declare
d content_dir;
begin
with recursive path as (
(select dir.id as dir_id, dir_entry_f.name as name, 0 as depth
from directory_entry_file as dir_entry_f
join content on content.sha1_git = dir_entry_f.target
join directory as dir on dir.file_entries @> array[dir_entry_f.id]
where content.sha1 = content_id
limit 1)
union all
(select dir.id as dir_id,
(dir_entry_d.name || '/' || path.name)::unix_path as name,
path.depth + 1
from path
join directory_entry_dir as dir_entry_d on dir_entry_d.target = path.dir_id
join directory as dir on dir.dir_entries @> array[dir_entry_d.id]
limit 1)
)
select dir_id, name from path order by depth desc limit 1
into strict d;
return d;
end
$$;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment