Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save peterbe/f83f55ad5fcf21a71d4f882ce0e91419 to your computer and use it in GitHub Desktop.
Save peterbe/f83f55ad5fcf21a71d4f882ce0e91419 to your computer and use it in GitHub Desktop.
postgres logs, batched get_all from kinto (BEFORE)
2018-05-03 09:53:41.222 EDT [2708] LOG: statement: BEGIN
2018-05-03 09:53:41.222 EDT [2708] LOG: statement:
SELECT principal
FROM user_principals
WHERE user_id = 'basicauth:a9302d2ec674f91c44359646adaf7c51070ef4a3699ca596f22a543954e38c32'
OR user_id = 'system.Authenticated';
2018-05-03 09:53:41.223 EDT [2708] LOG: statement:
WITH required_perms AS (
VALUES ('/buckets/build-hub/collections/releases', 'read'),('/buckets/build-hub/collections/releases', 'write'),('/buckets/build-hub', 'read'),('/buckets/build-hub', 'write')
),
allowed_principals AS (
SELECT principal
FROM required_perms JOIN access_control_entries
ON (object_id = column1 AND permission = column2)
),
required_principals AS (
VALUES ('basicauth:a9302d2ec674f91c44359646adaf7c51070ef4a3699ca596f22a543954e38c32'),('system.Everyone'),('system.Authenticated')
)
SELECT COUNT(*) AS matched
FROM required_principals JOIN allowed_principals
ON (required_principals.column1 = principal);
2018-05-03 09:53:41.223 EDT [2708] LOG: statement:
SELECT as_epoch(last_modified) AS last_modified, data
FROM records
WHERE id = 'releases'
AND parent_id = '/buckets/build-hub'
AND collection_id = 'collection'
AND NOT deleted;
2018-05-03 09:53:41.224 EDT [2708] LOG: statement:
WITH existing_timestamps AS (
-- Timestamp of latest record.
(
SELECT last_modified, as_epoch(last_modified) AS last_epoch
FROM records
WHERE parent_id = '/buckets/build-hub/collections/releases'
AND collection_id = 'record'
ORDER BY last_modified DESC
LIMIT 1
)
-- Timestamp of empty collection.
UNION
(
SELECT last_modified, as_epoch(last_modified) AS last_epoch
FROM timestamps
WHERE parent_id = '/buckets/build-hub/collections/releases'
AND collection_id = 'record'
)
)
SELECT MAX(last_modified) AS last_modified, MAX(last_epoch) AS last_epoch
FROM existing_timestamps
2018-05-03 09:53:41.225 EDT [2708] LOG: statement:
INSERT INTO timestamps (parent_id, collection_id, last_modified)
VALUES ('/buckets/build-hub/collections/releases', 'record', COALESCE('2018-05-02T18:05:03.336767'::timestamp, clock_timestamp()::timestamp))
ON CONFLICT (parent_id, collection_id) DO NOTHING
RETURNING as_epoch(last_modified) AS last_epoch
2018-05-03 09:53:41.226 EDT [2708] LOG: statement:
WITH collection_filtered AS (
SELECT id, last_modified, data, deleted
FROM records
WHERE parent_id = '/buckets/build-hub/collections/releases'
AND collection_id = 'record'
AND NOT deleted
),
total_filtered AS (
SELECT COUNT(id) AS count_total
FROM collection_filtered
WHERE NOT deleted
),
paginated_records AS (
SELECT DISTINCT id
FROM collection_filtered
WHERE (as_epoch(last_modified) < 1524589243612)
)
SELECT count_total,
a.id, as_epoch(a.last_modified) AS last_modified, a.data
FROM paginated_records AS p JOIN collection_filtered AS a ON (a.id = p.id),
total_filtered
ORDER BY last_modified DESC
LIMIT 10000;
2018-05-03 09:54:01.856 EDT [2708] LOG: statement: COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment