Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-archiver
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Platform
Development
swh-archiver
Commits
8ad17ae3
Commit
8ad17ae3
authored
8 years ago
by
Nicolas Dandrimont
Browse files
Options
Downloads
Patches
Plain Diff
sql/archiver: move function defs to the functions file
parent
36d76764
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sql/swh-archiver-func.sql
+30
-0
30 additions, 0 deletions
sql/swh-archiver-func.sql
sql/swh-archiver-schema.sql
+0
-30
0 additions, 30 deletions
sql/swh-archiver-schema.sql
with
30 additions
and
30 deletions
sql/swh-archiver-func.sql
+
30
−
0
View file @
8ad17ae3
...
...
@@ -46,3 +46,33 @@ end
$$
;
COMMENT
ON
FUNCTION
swh_content_archive_unknown
()
IS
'Retrieve list of unknown sha1s'
;
CREATE
OR
REPLACE
FUNCTION
count_copies
(
from_id
bytea
,
to_id
bytea
)
returns
void
language
sql
as
$$
with
sample
as
(
select
content_id
,
copies
from
content_archive
where
content_id
>
from_id
and
content_id
<=
to_id
),
data
as
(
select
substring
(
content_id
from
19
)
as
bucket
,
jbe
.
key
as
archive
from
sample
join
lateral
jsonb_each
(
copies
)
jbe
on
true
where
jbe
.
value
->>
'status'
=
'present'
),
bucketed
as
(
select
bucket
,
archive
,
count
(
*
)
as
count
from
data
group
by
bucket
,
archive
)
update
content_archive_counts
cac
set
count
=
cac
.
count
+
bucketed
.
count
from
bucketed
where
cac
.
archive
=
bucketed
.
archive
and
cac
.
bucket
=
bucketed
.
bucket
;
$$
;
comment
on
function
count_copies
(
bytea
,
bytea
)
is
'Count the objects between from_id and to_id, add the results to content_archive_counts'
;
CREATE
OR
REPLACE
FUNCTION
init_content_archive_counts
()
returns
void
language
sql
as
$$
insert
into
content_archive_counts
(
select
id
,
decode
(
lpad
(
to_hex
(
bucket
),
4
,
'0'
),
'hex'
)::
bucket
as
bucket
,
0
as
count
from
archive
join
lateral
generate_series
(
0
,
65535
)
bucket
on
true
)
on
conflict
(
archive
,
bucket
)
do
nothing
;
$$
;
comment
on
function
init_content_archive_counts
()
is
'Initialize the content archive counts for the registered archives'
;
This diff is collapsed.
Click to expand it.
sql/swh-archiver-schema.sql
+
0
−
30
View file @
8ad17ae3
...
...
@@ -73,36 +73,6 @@ CREATE TRIGGER update_num_present
FOR
EACH
ROW
EXECUTE
PROCEDURE
update_num_present
();
CREATE
FUNCTION
count_copies
(
from_id
bytea
,
to_id
bytea
)
returns
void
language
sql
as
$$
with
sample
as
(
select
content_id
,
copies
from
content_archive
where
content_id
>
from_id
and
content_id
<=
to_id
),
data
as
(
select
substring
(
content_id
from
19
)
as
bucket
,
jbe
.
key
as
archive
from
sample
join
lateral
jsonb_each
(
copies
)
jbe
on
true
where
jbe
.
value
->>
'status'
=
'present'
),
bucketed
as
(
select
bucket
,
archive
,
count
(
*
)
as
count
from
data
group
by
bucket
,
archive
)
update
content_archive_counts
cac
set
count
=
cac
.
count
+
bucketed
.
count
from
bucketed
where
cac
.
archive
=
bucketed
.
archive
and
cac
.
bucket
=
bucketed
.
bucket
;
$$
;
comment
on
function
count_copies
(
bytea
,
bytea
)
is
'Count the objects between from_id and to_id, add the results to content_archive_counts'
;
CREATE
FUNCTION
init_content_archive_counts
()
returns
void
language
sql
as
$$
insert
into
content_archive_counts
(
select
id
,
decode
(
lpad
(
to_hex
(
bucket
),
4
,
'0'
),
'hex'
)::
bucket
as
bucket
,
0
as
count
from
archive
join
lateral
generate_series
(
0
,
65535
)
bucket
on
true
)
on
conflict
(
archive
,
bucket
)
do
nothing
;
$$
;
comment
on
function
init_content_archive_counts
()
is
'Initialize the content archive counts for the registered archives'
;
-- keep the content_archive_counts updated
CREATE
FUNCTION
update_content_archive_counts
()
RETURNS
TRIGGER
LANGUAGE
PLPGSQL
AS
$$
DECLARE
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment