Skip to content

Commit

Permalink
fix: performance metrics queries (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored Nov 15, 2021
1 parent d1d9aa3 commit 85efba5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
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

0 comments on commit 85efba5

Please sign in to comment.