Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: performance metrics queries #625

Merged
merged 2 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* https://github.com/sinedied/smoke#javascript-mocks
*/
module.exports = () => {
return {
statusCode: 200,
body: '30000'
}
}
13 changes: 13 additions & 0 deletions packages/db/postgres/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ SELECT (ak.id)::TEXT AS id,
WHERE ak.user_id = query_user_id AND ak.deleted_at IS NULL
$$;

CREATE OR REPLACE FUNCTION pin_from_status_total(query_status TEXT) RETURNS TEXT
LANGUAGE plpgsql
AS
$$
BEGIN
return(
select count(*)
from pin
where status = (query_status)::pin_status_type
)::TEXT;
END
$$;

CREATE OR REPLACE FUNCTION content_dag_size_total() RETURNS TEXT
LANGUAGE plpgsql
AS
Expand Down
6 changes: 1 addition & 5 deletions packages/db/postgres/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ const pinStatusMapping = {

export async function getPinStatusMetrics (client, key) {
const pinStatus = pinStatusMapping[key]
const { count, error } = await client
.from('pin')
.select('*', { head: true, count: 'exact' })
.filter('status', 'eq', pinStatus)
.range(0, 1)
const { count, error } = await client.rpc('pin_from_status_total', { query_status: pinStatus })

if (error) {
throw new DBError(error)
Expand Down
2 changes: 2 additions & 0 deletions packages/db/postgres/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ CREATE TABLE IF NOT EXISTS content
);

CREATE INDEX IF NOT EXISTS content_updated_at_idx ON content (updated_at);
-- TODO: Sync with @ribasushi as we can start using this as the primary key
CREATE UNIQUE INDEX content_cid_with_size_idx ON content (cid) INCLUDE (dag_size);

-- IPFS Cluster tracker status values.
-- https://github.com/ipfs/ipfs-cluster/blob/54c3608899754412861e69ee81ca8f676f7e294b/api/types.go#L52-L83
Expand Down