Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7450772
039.sql
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
039.sql
View Options
-- SWH DB schema upgrade
-- from_version: 38
-- to_version: 39
-- description: Improve find directory entry by path
insert
into
dbversion
(
version
,
release
,
description
)
values
(
39
,
now
(),
'Work In Progress'
);
-- Find a directory entry by its path
create
or
replace
function
swh_find_directory_entry_by_path
(
walked_dir_id
sha1_git
,
dir_or_content_path
bytea
[])
returns
directory_entry
language
plpgsql
as
$$
declare
end_index
integer
;
paths
bytea
default
''
;
path
bytea
;
res
bytea
[];
r
record
;
begin
end_index
:
=
array_upper
(
dir_or_content_path
,
1
);
res
[
1
]
:
=
walked_dir_id
;
for
i
in
1
..
end_index
loop
path
:
=
dir_or_content_path
[
i
];
-- concatenate path for patching the name in the result record (if we found it)
if
i
=
1
then
paths
=
path
;
else
paths
:
=
paths
||
'/'
||
path
;
-- concatenate paths
end
if
;
if
i
<>
end_index
then
select
*
from
swh_directory_walk_one
(
res
[
i
]
::
sha1_git
)
where
name
=
path
and
type
=
'dir'
limit
1
into
r
;
else
select
*
from
swh_directory_walk_one
(
res
[
i
]
::
sha1_git
)
where
name
=
path
limit
1
into
r
;
end
if
;
-- find the path
if
r
is
null
then
return
null
;
else
-- store the next dir to lookup the next local path from
res
[
i
+
1
]
:
=
r
.
target
;
end
if
;
end
loop
;
-- at this moment, r is the result. Patch its 'name' with the full path before returning it.
r
.
name
:
=
paths
;
return
r
;
end
$$
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 17, 8:39 AM (4 d, 6 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3245596
Attached To
rDSTOC swh-storage-cassandra
Event Timeline
Log In to Comment