Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hive/hivemind
1 result
Show changes
Commits on Source (32)
Showing
with 849 additions and 479 deletions
stages:
- build
- test
- data-supply
- deploy
- e2e-test
- benchmark-tests
- post-deploy
.dk-setup-pip: &dk-setup-pip
- python -m venv .venv
- source .venv/bin/activate
- time pip install --upgrade pip setuptools wheel
- pip --version
- easy_install --version
- wheel version
- pipenv --version
- poetry --version
- time pip install --editable .[dev]
.dk-setup-runner-env: &dk-setup-runner-env
# Setup runner environment (to connect to correct postgres server, mainly).
- TMP_VAR=$(cat hive-sync-runner-id.txt 2>/dev/null || true); export HIVE_SYNC_RUNNER_ID=${TMP_VAR:-0}
- eval $(cat "$RUNNER_CONF" | ./scripts/ci/setup_env.py --current-runner-id=${CI_RUNNER_ID} --hive-sync-runner-id=${HIVE_SYNC_RUNNER_ID})
.dk-set-variables: &dk-set-variables
# - export # List all variables and its values set by Gitlab CI.
- whoami
- echo "CI_RUNNER_ID is $CI_RUNNER_ID"
- echo "CI_PIPELINE_URL is $CI_PIPELINE_URL"
- echo "CI_PIPELINE_ID is $CI_PIPELINE_ID"
- echo "CI_COMMIT_SHORT_SHA is $CI_COMMIT_SHORT_SHA"
- echo "CI_COMMIT_REF_SLUG is $CI_COMMIT_REF_SLUG"
- export HIVEMIND_DB_NAME=${HIVEMIND_DB_NAME//[^a-zA-Z0-9_]/_}
- echo "HIVEMIND_DB_NAME is $HIVEMIND_DB_NAME"
.dk-fetch-git-tags: &dk-fetch-git-tags
# - git fetch --tags # Looks to be unnecessary.
- git tag -f ci_implicit_tag # Needed to build python package
.dk-start-timer: &dk-start-timer
- ./scripts/ci/timer.sh start
.dk-stop-timer: &dk-stop-timer
- ./scripts/ci/timer.sh check
.dk-hive-sync-script-common: &dk-hive-sync-script-common
- echo "${CI_RUNNER_ID}" > hive-sync-runner-id.txt
- ./scripts/ci/wait-for-postgres.sh "$RUNNER_POSTGRES_HOST" "$RUNNER_POSTGRES_PORT"
- export POSTGRES_MAJOR_VERSION=$(./scripts/ci/get-postgres-version.sh)
- ./scripts/ci/create-db.sh
- ./scripts/ci/hive-sync.sh
- ./scripts/ci/collect-db-stats.sh
.dk-rules-for-sync: &dk-rules-for-sync
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: always
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: always
- if: '$CI_COMMIT_BRANCH == "develop"'
when: always
- if: '$CI_PIPELINE_SOURCE == "push"'
when: manual
- when: manual
.dk-rules-for-test: &dk-rules-for-test
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: on_success
- if: '$CI_PIPELINE_SOURCE == "push"'
when: on_success
- when: on_success
.dk-default:
image: hivemind/python:3.6
interruptible: true
inherit:
default: false
variables: false
variables:
GIT_DEPTH: 10
GIT_STRATEGY: fetch
GIT_SUBMODULE_STRATEGY: recursive
PIPENV_VENV_IN_PROJECT: 1
PIPENV_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pipenv"
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
POSTGRES_CLIENT_TOOLS_PATH: /usr/lib/postgresql
HIVEMIND_DB_NAME: "hive_${CI_COMMIT_REF_SLUG}"
cache: &dk-global-cache
# Per-branch caching. CI_COMMIT_REF_SLUG is the same thing.
# key: "$CI_COMMIT_REF_NAME"
# Per project caching – use any key.
# Change this key, if you need to clear cache.
key: common-1
paths:
- .cache/
- .venv/
- .tox/
before_script:
- *dk-start-timer
- *dk-fetch-git-tags
- *dk-set-variables
- *dk-setup-pip
- *dk-setup-runner-env
after_script:
- *dk-stop-timer
##### Jobs #####
dk-hivemind-sync:
# Postgres shared on host.
extends: .dk-default
<<: *dk-rules-for-sync
stage: data-supply
needs: []
script:
- *dk-hive-sync-script-common
artifacts:
paths:
- hivemind-sync.log
- pg-stats
- hive-sync-runner-id.txt
expire_in: 7 days
tags:
- hivemind-heavy-job
.dk-test-common:
extends: .dk-default
<<: *dk-rules-for-test
needs:
- job: dk-hivemind-sync
artifacts: true
allow_failure: false
before_script:
- *dk-start-timer
- *dk-fetch-git-tags
- *dk-set-variables
- *dk-setup-pip
- *dk-setup-runner-env
- ./scripts/ci/wait-for-postgres.sh "$RUNNER_POSTGRES_HOST" "$RUNNER_POSTGRES_PORT"
- ./scripts/ci/hive-server.sh start
after_script:
- *dk-stop-timer
tags:
- hivemind-light-job
dk-bridge_api_smoketest:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
bridge_api_patterns/ api_smoketest_bridge.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_bridge.xml
dk-bridge_api_smoketest_negative:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
bridge_api_negative/ api_smoketest_bridge_negative.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_bridge_negative.xml
dk-condenser_api_smoketest:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
condenser_api_patterns/ api_smoketest_condenser_api.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_condenser_api.xml
dk-condenser_api_smoketest_negative:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
condenser_api_negative/ api_smoketest_condenser_api_negative.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_condenser_api_negative.xml
dk-database_api_smoketest:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
database_api_patterns/ api_smoketest_database_api.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_database_api.xml
dk-database_api_smoketest_negative:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
database_api_negative/ api_smoketest_database_api_negative.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_database_api_negative.xml
dk-follow_api_smoketest:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
follow_api_patterns/ api_smoketest_follow_api.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest.xml
dk-follow_api_smoketest_negative:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
follow_api_negative/ api_smoketest_follow_api_negative.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_follow_api_negative.xml
dk-tags_api_smoketest:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
tags_api_negative/ api_smoketest_tags_api_negative.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_tags_api_negative.xml
dk-tags_api_smoketest_negative:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
tags_api_patterns/ api_smoketest_tags_api.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_tags_api.xml
dk-mock_tests:
stage: e2e-test
extends: .dk-test-common
script:
- |
scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
mock_tests/ api_smoketest_mock_tests.xml \
$RUNNER_TEST_JOBS
dk-api-smoketest-benchmark:
stage: benchmark-tests
extends: .dk-test-common
# Temporary failure (when any call is longer than 1s is allowed)
allow_failure: true
script:
- |
./scripts/ci/start-api-benchmarks.sh \
localhost $RUNNER_HIVEMIND_SERVER_HTTP_PORT 5 \
$RUNNER_TEST_JOBS
- ./scripts/xml_report_parser.py . ./tests/tests_api/hivemind/tavern
artifacts:
when: always
paths:
- tavern_benchmarks_report.html
stages:
- build
- test
- data-supply
- deploy
- e2e-test
- benchmark-tests
- post-deploy
.dk-setup-pip: &dk-setup-pip
- python -m venv .venv
- source .venv/bin/activate
- time pip install --upgrade pip setuptools wheel
- pip --version
- easy_install --version
- wheel version
- pipenv --version
- poetry --version
- time pip install --editable .[dev]
.dk-setup-runner-env: &dk-setup-runner-env
# Setup runner environment (to connect to correct postgres server, mainly).
- TMP_VAR=$(cat hive-sync-runner-id.txt 2>/dev/null || true); export HIVE_SYNC_RUNNER_ID=${TMP_VAR:-0}
- eval $(cat "$RUNNER_CONF" | ./scripts/ci/setup_env.py --current-runner-id=${CI_RUNNER_ID} --hive-sync-runner-id=${HIVE_SYNC_RUNNER_ID})
.dk-set-variables: &dk-set-variables
# - export # List all variables and its values set by Gitlab CI.
- whoami
- echo "CI_RUNNER_ID is $CI_RUNNER_ID"
- echo "CI_PIPELINE_URL is $CI_PIPELINE_URL"
- echo "CI_PIPELINE_ID is $CI_PIPELINE_ID"
- echo "CI_COMMIT_SHORT_SHA is $CI_COMMIT_SHORT_SHA"
- echo "CI_COMMIT_REF_SLUG is $CI_COMMIT_REF_SLUG"
- export HIVEMIND_DB_NAME=${HIVEMIND_DB_NAME//[^a-zA-Z0-9_]/_}
- echo "HIVEMIND_DB_NAME is $HIVEMIND_DB_NAME"
.dk-fetch-git-tags: &dk-fetch-git-tags
# - git fetch --tags # Looks to be unnecessary.
- git tag -f ci_implicit_tag # Needed to build python package
.dk-start-timer: &dk-start-timer
- ./scripts/ci/timer.sh start
.dk-stop-timer: &dk-stop-timer
- ./scripts/ci/timer.sh check
.dk-hive-sync-script-common: &dk-hive-sync-script-common
- echo "${CI_RUNNER_ID}" > hive-sync-runner-id.txt
- ./scripts/ci/wait-for-postgres.sh "$RUNNER_POSTGRES_HOST" "$RUNNER_POSTGRES_PORT"
- export POSTGRES_MAJOR_VERSION=$(./scripts/ci/get-postgres-version.sh)
- ./scripts/ci/create-db.sh
- ./scripts/ci/hive-sync.sh
- ./scripts/ci/collect-db-stats.sh
.dk-rules-for-sync: &dk-rules-for-sync
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: always
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: always
- if: '$CI_COMMIT_BRANCH == "develop"'
when: always
- if: '$CI_PIPELINE_SOURCE == "push"'
when: manual
- when: manual
.dk-rules-for-test: &dk-rules-for-test
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: on_success
- if: '$CI_PIPELINE_SOURCE == "push"'
when: on_success
- when: on_success
.dk-default:
image: hivemind/python:3.6
interruptible: true
inherit:
default: false
variables: false
variables:
GIT_DEPTH: 10
GIT_STRATEGY: fetch
GIT_SUBMODULE_STRATEGY: recursive
PIPENV_VENV_IN_PROJECT: 1
PIPENV_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pipenv"
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
POSTGRES_CLIENT_TOOLS_PATH: /usr/lib/postgresql
HIVEMIND_DB_NAME: "hive_${CI_COMMIT_REF_SLUG}"
cache: &dk-global-cache
# Per-branch caching. CI_COMMIT_REF_SLUG is the same thing.
# key: "$CI_COMMIT_REF_NAME"
# Per project caching – use any key.
# Change this key, if you need to clear cache.
key: common-1
paths:
- .cache/
- .venv/
- .tox/
before_script:
- *dk-start-timer
- *dk-fetch-git-tags
- *dk-set-variables
- *dk-setup-pip
- *dk-setup-runner-env
after_script:
- *dk-stop-timer
##### Jobs #####
dk-hivemind-sync:
# Postgres shared on host.
extends: .dk-default
<<: *dk-rules-for-sync
stage: data-supply
needs: []
script:
- *dk-hive-sync-script-common
artifacts:
paths:
- hivemind-sync.log
- pg-stats
- hive-sync-runner-id.txt
expire_in: 7 days
tags:
- hivemind-heavy-job
.dk-test-common:
extends: .dk-default
<<: *dk-rules-for-test
needs:
- job: dk-hivemind-sync
artifacts: true
allow_failure: false
before_script:
- *dk-start-timer
- *dk-fetch-git-tags
- *dk-set-variables
- *dk-setup-pip
- *dk-setup-runner-env
- ./scripts/ci/wait-for-postgres.sh "$RUNNER_POSTGRES_HOST" "$RUNNER_POSTGRES_PORT"
- ./scripts/ci/hive-server.sh start
after_script:
- *dk-stop-timer
tags:
- hivemind-light-job
dk-bridge_api_smoketest:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
bridge_api_patterns/ api_smoketest_bridge.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_bridge.xml
dk-bridge_api_smoketest_negative:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
bridge_api_negative/ api_smoketest_bridge_negative.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_bridge_negative.xml
dk-condenser_api_smoketest:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
condenser_api_patterns/ api_smoketest_condenser_api.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_condenser_api.xml
dk-condenser_api_smoketest_negative:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
condenser_api_negative/ api_smoketest_condenser_api_negative.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_condenser_api_negative.xml
dk-database_api_smoketest:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
database_api_patterns/ api_smoketest_database_api.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_database_api.xml
dk-database_api_smoketest_negative:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
database_api_negative/ api_smoketest_database_api_negative.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_database_api_negative.xml
dk-follow_api_smoketest:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
follow_api_patterns/ api_smoketest_follow_api.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_follow_api.xml
dk-follow_api_smoketest_negative:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
follow_api_negative/ api_smoketest_follow_api_negative.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_follow_api_negative.xml
dk-hive_api_smoketest:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
hive_api_patterns/ api_smoketest_hive_api.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_hive_api.xml
dk-tags_api_smoketest:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
tags_api_patterns/ api_smoketest_tags_api.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_tags_api.xml
dk-tags_api_smoketest_negative:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
tags_api_negative/ api_smoketest_tags_api_negative.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_tags_api_negative.xml
dk-mock_tests:
stage: e2e-test
extends: .dk-test-common
script:
- |
./scripts/ci/start-api-smoketest.sh \
localhost "$RUNNER_HIVEMIND_SERVER_HTTP_PORT" \
mock_tests/ api_smoketest_mock_tests.xml \
$RUNNER_TEST_JOBS
artifacts:
when: always
reports:
junit: api_smoketest_mock_tests.xml
dk-api-smoketest-benchmark:
stage: benchmark-tests
extends: .dk-test-common
# Temporary failure (when any call is longer than 1s is allowed)
allow_failure: true
script:
- |
./scripts/ci/start-api-benchmarks.sh \
localhost $RUNNER_HIVEMIND_SERVER_HTTP_PORT 5 \
$RUNNER_TEST_JOBS
- ./scripts/xml_report_parser.py . ./tests/tests_api/hivemind/tavern
artifacts:
when: always
paths:
- tavern_benchmarks_report.html
......@@ -564,12 +564,14 @@ def setup(db):
"hive_posts_view.sql",
"hive_votes_view.sql",
"hive_muted_accounts_view.sql",
"hive_muted_accounts_by_id_view.sql",
"hive_post_operations.sql",
"head_block_time.sql",
"update_feed_cache.sql",
"payout_stats_view.sql",
"update_hive_posts_mentions.sql",
"find_tag_id.sql",
"mutes.sql",
"bridge_get_ranked_post_type.sql",
"bridge_get_ranked_post_for_communities.sql",
"bridge_get_ranked_post_for_observer_communities.sql",
......
......@@ -60,6 +60,7 @@ BEGIN
hp.role_id,
hp.is_pinned,
hp.curator_payout_value,
hp.is_muted,
T.reblogged_by
FROM hive_posts_view hp
JOIN
......
......@@ -5,33 +5,29 @@ CREATE OR REPLACE FUNCTION get_discussion(
in _permlink hive_permlink_data.permlink%TYPE,
in _observer VARCHAR
)
RETURNS TABLE
(
id hive_posts.id%TYPE, parent_id hive_posts.parent_id%TYPE, author hive_accounts.name%TYPE, permlink hive_permlink_data.permlink%TYPE,
title hive_post_data.title%TYPE, body hive_post_data.body%TYPE, category hive_category_data.category%TYPE, depth hive_posts.depth%TYPE,
promoted hive_posts.promoted%TYPE, payout hive_posts.payout%TYPE, pending_payout hive_posts.pending_payout%TYPE, payout_at hive_posts.payout_at%TYPE,
is_paidout hive_posts.is_paidout%TYPE, children hive_posts.children%TYPE, created_at hive_posts.created_at%TYPE, updated_at hive_posts.updated_at%TYPE,
rshares hive_posts_view.rshares%TYPE, abs_rshares hive_posts_view.abs_rshares%TYPE, json hive_post_data.json%TYPE, author_rep hive_accounts.reputation%TYPE,
is_hidden hive_posts.is_hidden%TYPE, is_grayed BOOLEAN, total_votes BIGINT, sc_trend hive_posts.sc_trend%TYPE,
acct_author_id hive_posts.author_id%TYPE, root_author hive_accounts.name%TYPE, root_permlink hive_permlink_data.permlink%TYPE,
parent_author hive_accounts.name%TYPE, parent_permlink_or_category hive_permlink_data.permlink%TYPE, allow_replies BOOLEAN,
allow_votes hive_posts.allow_votes%TYPE, allow_curation_rewards hive_posts.allow_curation_rewards%TYPE, url TEXT, root_title hive_post_data.title%TYPE,
beneficiaries hive_posts.beneficiaries%TYPE, max_accepted_payout hive_posts.max_accepted_payout%TYPE, percent_hbd hive_posts.percent_hbd%TYPE,
curator_payout_value hive_posts.curator_payout_value%TYPE
)
RETURNS SETOF bridge_api_post_discussion
LANGUAGE plpgsql
AS
$function$
DECLARE
__post_id INT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
RETURN QUERY
SELECT
hpv.id,
hpv.parent_id,
hpv.author,
hpv.parent_author,
hpv.author_rep,
hpv.root_title,
hpv.beneficiaries,
hpv.max_accepted_payout,
hpv.percent_hbd,
hpv.url,
hpv.permlink,
hpv.parent_permlink_or_category,
hpv.title,
hpv.body,
hpv.category,
......@@ -42,30 +38,23 @@ BEGIN
hpv.payout_at,
hpv.is_paidout,
hpv.children,
hpv.votes,
hpv.created_at,
hpv.updated_at,
hpv.rshares,
hpv.abs_rshares,
hpv.json,
hpv.author_rep,
hpv.is_hidden,
hpv.is_grayed,
hpv.total_votes,
hpv.sc_trend,
hpv.author_id AS acct_author_id,
hpv.root_author,
hpv.root_permlink,
hpv.parent_author,
hpv.parent_permlink_or_category,
hpv.allow_replies,
hpv.allow_votes,
hpv.allow_curation_rewards,
hpv.url,
hpv.root_title,
hpv.beneficiaries,
hpv.max_accepted_payout,
hpv.percent_hbd,
hpv.curator_payout_value
hpv.role_title,
hpv.community_title,
hpv.role_id,
hpv.is_pinned,
hpv.curator_payout_value,
hpv.is_muted,
hpv.parent_id
FROM
(
WITH RECURSIVE child_posts (id, parent_id) AS
......@@ -73,13 +62,14 @@ BEGIN
SELECT hp.id, hp.parent_id
FROM hive_posts hp
WHERE hp.id = __post_id
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp.author_id))
UNION ALL
SELECT children.id, children.parent_id
FROM hive_posts children
JOIN child_posts ON children.parent_id = child_posts.id
JOIN hive_accounts ON children.author_id = hive_accounts.id
WHERE children.counter_deleted = 0 AND
(CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hive_accounts.name) ELSE True END)
WHERE children.counter_deleted = 0
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = children.author_id))
)
SELECT hp2.id
FROM hive_posts hp2
......
......@@ -5,8 +5,10 @@ AS
$function$
DECLARE
__post_id INT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -52,11 +54,11 @@ BEGIN
FROM hive_posts hp1
JOIN hive_accounts_view ha ON hp1.author_id = ha.id
WHERE hp1.counter_deleted = 0 AND hp1.depth = 0 AND NOT ha.is_grayed AND ( __post_id = 0 OR hp1.id < __post_id )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY hp1.id DESC
LIMIT _limit
) as created
JOIN hive_posts_view hp ON hp.id = created.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
ORDER BY created.id DESC
LIMIT _limit;
END
......@@ -71,8 +73,10 @@ $function$
DECLARE
__post_id INT;
__hot_limit FLOAT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
IF __post_id <> 0 THEN
SELECT hp.sc_hot INTO __hot_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -123,11 +127,11 @@ BEGIN
hive_posts hp1
WHERE hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0
AND ( __post_id = 0 OR hp1.sc_hot < __hot_limit OR ( hp1.sc_hot = __hot_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY hp1.sc_hot DESC, hp1.id DESC
LIMIT _limit
) as hot
JOIN hive_posts_view hp ON hp.id = hot.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
ORDER BY hot.hot DESC, hot.id DESC
LIMIT _limit;
END
......@@ -199,7 +203,6 @@ BEGIN
LIMIT _limit
) as payout
JOIN hive_posts_view hp ON hp.id = payout.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
ORDER BY payout.all_payout DESC, payout.id DESC
LIMIT _limit;
END
......@@ -214,8 +217,10 @@ $function$
DECLARE
__post_id INT;
__payout_limit hive_posts.payout%TYPE;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
IF __post_id <> 0 THEN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -266,11 +271,11 @@ BEGIN
hive_posts hp1
WHERE hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth > 0
AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY ( hp1.payout + hp1.pending_payout ) DESC, hp1.id DESC
LIMIT _limit
) as payout
JOIN hive_posts_view hp ON hp.id = payout.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
ORDER BY payout.all_payout DESC, payout.id DESC
LIMIT _limit;
END
......@@ -286,8 +291,10 @@ DECLARE
__post_id INT;
__payout_limit hive_posts.payout%TYPE;
__head_block_time TIMESTAMP;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
IF __post_id <> 0 THEN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -340,11 +347,11 @@ BEGIN
WHERE hp1.counter_deleted = 0 AND NOT hp1.is_paidout
AND ( ( NOT _bridge_api AND hp1.depth = 0 ) OR ( _bridge_api AND hp1.payout_at BETWEEN __head_block_time + interval '12 hours' AND __head_block_time + interval '36 hours' ) )
AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY ( hp1.payout + hp1.pending_payout ) DESC, hp1.id DESC
LIMIT _limit
) as payout
JOIN hive_posts_view hp ON hp.id = payout.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
ORDER BY payout.all_payout DESC, payout.id DESC
LIMIT _limit;
END
......@@ -359,8 +366,10 @@ $function$
DECLARE
__post_id INT;
__promoted_limit hive_posts.promoted%TYPE;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
IF __post_id <> 0 THEN
SELECT hp.promoted INTO __promoted_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -411,11 +420,11 @@ BEGIN
hive_posts hp1
WHERE hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.promoted > 0
AND ( __post_id = 0 OR hp1.promoted < __promoted_limit OR ( hp1.promoted = __promoted_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY hp1.promoted DESC, hp1.id DESC
LIMIT _limit
) as promoted
JOIN hive_posts_view hp ON hp.id = promoted.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
ORDER BY promoted.promoted DESC, promoted.id DESC
LIMIT _limit;
END
......@@ -430,8 +439,10 @@ $function$
DECLARE
__post_id INT;
__trending_limit FLOAT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
IF __post_id <> 0 THEN
SELECT hp.sc_trend INTO __trending_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -482,11 +493,11 @@ BEGIN
hive_posts hp1
WHERE hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0
AND ( __post_id = 0 OR hp1.sc_trend < __trending_limit OR ( hp1.sc_trend = __trending_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY hp1.sc_trend DESC, hp1.id DESC
LIMIT _limit
) as trends
JOIN hive_posts_view hp ON hp.id = trends.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
ORDER BY trends.trend DESC, trends.id DESC
LIMIT _limit;
END
......
......@@ -3,7 +3,11 @@ CREATE FUNCTION bridge_get_ranked_post_pinned_for_community( in _community VARCH
RETURNS SETOF bridge_api_post
AS
$function$
SELECT
DECLARE
__observer_id INT;
BEGIN
__observer_id = find_account_id(_observer, False);
RETURN QUERY SELECT
hp.id,
hp.author,
hp.parent_author,
......@@ -45,11 +49,12 @@ $function$
hive_posts_view hp
JOIN hive_communities hc ON hc.id = hp.community_id
WHERE hc.name = _community AND hp.is_pinned
AND (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp.author_id))
ORDER BY hp.id DESC
LIMIT _limit;
END
$function$
language sql STABLE;
language plpgsql STABLE;
DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_trends_for_community;
CREATE FUNCTION bridge_get_ranked_post_by_trends_for_community( in _community VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT, in _bridge_api BOOLEAN, in _observer VARCHAR )
......@@ -59,8 +64,10 @@ $function$
DECLARE
__post_id INT;
__trending_limit FLOAT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
IF __post_id <> 0 THEN
SELECT hp.sc_trend INTO __trending_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -113,11 +120,11 @@ BEGIN
WHERE hc.name = _community AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0
AND ( NOT _bridge_api OR NOT hp1.is_pinned ) -- concatenated with bridge_get_ranked_post_pinned_for_community when called for bridge_api
AND ( __post_id = 0 OR hp1.sc_trend < __trending_limit OR ( hp1.sc_trend = __trending_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY hp1.sc_trend DESC, hp1.id DESC
LIMIT _limit
) as trends
JOIN hive_posts_view hp ON hp.id = trends.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY trends.trend DESC, trends.id DESC
LIMIT _limit;
END
......@@ -132,8 +139,10 @@ $function$
DECLARE
__post_id INT;
__promoted_limit hive_posts.promoted%TYPE;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
IF __post_id <> 0 THEN
SELECT hp.promoted INTO __promoted_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -185,11 +194,11 @@ BEGIN
JOIN hive_communities hc ON hp1.community_id = hc.id
WHERE hc.name = _community AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.promoted > 0
AND ( __post_id = 0 OR hp1.promoted < __promoted_limit OR ( hp1.promoted = __promoted_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY hp1.promoted DESC, hp1.id DESC
LIMIT _limit
) as promoted
JOIN hive_posts_view hp ON hp.id = promoted.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY promoted.promoted DESC, promoted.id DESC
LIMIT _limit;
END
......@@ -205,8 +214,10 @@ DECLARE
__post_id INT;
__payout_limit hive_posts.payout%TYPE;
__head_block_time TIMESTAMP;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id( _observer, False );
IF __post_id <> 0 THEN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -259,11 +270,11 @@ BEGIN
JOIN hive_communities hc ON hp1.community_id = hc.id
WHERE hc.name = _community AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.payout_at BETWEEN __head_block_time + interval '12 hours' AND __head_block_time + interval '36 hours'
AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY ( hp1.payout + hp1.pending_payout ) DESC, hp1.id DESC
LIMIT _limit
) as payout
JOIN hive_posts_view hp ON hp.id = payout.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY payout.all_payout DESC, payout.id DESC
LIMIT _limit;
END
......@@ -278,8 +289,10 @@ $function$
DECLARE
__post_id INT;
__payout_limit hive_posts.payout%TYPE;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
IF __post_id <> 0 THEN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -331,11 +344,11 @@ BEGIN
JOIN hive_communities hc ON hp1.community_id = hc.id
WHERE hc.name = _community AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth > 0
AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY ( hp1.payout + hp1.pending_payout ) DESC, hp1.id DESC
LIMIT _limit
) as payout
JOIN hive_posts_view hp ON hp.id = payout.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY payout.all_payout DESC, payout.id DESC
LIMIT _limit;
END
......@@ -408,7 +421,6 @@ BEGIN
LIMIT _limit
) as payout
JOIN hive_posts_view hp ON hp.id = payout.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY payout.all_payout DESC, payout.id DESC
LIMIT _limit;
END
......@@ -423,8 +435,10 @@ $function$
DECLARE
__post_id INT;
__hot_limit FLOAT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
IF __post_id <> 0 THEN
SELECT hp.sc_hot INTO __hot_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -476,11 +490,11 @@ BEGIN
JOIN hive_communities hc ON hp1.community_id = hc.id
WHERE hc.name = _community AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0
AND ( __post_id = 0 OR hp1.sc_hot < __hot_limit OR ( hp1.sc_hot = __hot_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY hp1.sc_hot DESC, hp1.id DESC
LIMIT _limit
) as hot
JOIN hive_posts_view hp ON hp.id = hot.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY hot.hot DESC, hot.id DESC
LIMIT _limit;
END
......@@ -494,8 +508,10 @@ AS
$function$
DECLARE
__post_id INT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -541,15 +557,14 @@ BEGIN
FROM
hive_posts hp1
JOIN hive_communities hc ON hp1.community_id = hc.id
JOIN hive_accounts_view ha ON hp1.author_id = ha.id
WHERE hc.name = _community AND hp1.counter_deleted = 0 AND hp1.depth = 0
AND ( NOT _bridge_api OR NOT hp1.is_pinned ) -- concatenated with bridge_get_ranked_post_pinned_for_community when called for bridge_api
AND NOT ha.is_grayed AND ( __post_id = 0 OR hp1.id < __post_id )
AND ( __post_id = 0 OR hp1.id < __post_id )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY hp1.id DESC
LIMIT _limit
) as created
JOIN hive_posts_view hp ON hp.id = created.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY created.id DESC
LIMIT _limit;
END
......
......@@ -52,7 +52,7 @@ BEGIN
JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
JOIN hive_accounts_view ha ON ha.id = hp.author_id
WHERE hs.account_id = __account_id AND hp.depth = 0 AND NOT ha.is_grayed AND ( __post_id = 0 OR hp.id < __post_id )
AND (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __account_id AND muted_id = hp.author_id))
ORDER BY hp.id DESC
LIMIT _limit;
END
......@@ -74,7 +74,7 @@ BEGIN
SELECT hp.sc_hot INTO __hot_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__account_id = find_account_id( _observer, True );
RETURN QUERY SELECT
RETURN QUERY SELECT
hp.id,
hp.author,
hp.parent_author,
......@@ -117,7 +117,7 @@ BEGIN
JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
WHERE hs.account_id = __account_id AND NOT hp.is_paidout AND hp.depth = 0
AND ( __post_id = 0 OR hp.sc_hot < __hot_limit OR ( hp.sc_hot = __hot_limit AND hp.id < __post_id ) )
AND (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __account_id AND muted_id = hp.author_id))
ORDER BY hp.sc_hot DESC, hp.id DESC
LIMIT _limit;
END
......@@ -187,11 +187,11 @@ BEGIN
JOIN hive_subscriptions hs ON hp1.community_id = hs.community_id
WHERE hs.account_id = __account_id AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth > 0
AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __account_id AND muted_id = hp1.author_id))
ORDER BY ( hp1.payout + hp1.pending_payout ) DESC, hp1.id DESC
LIMIT _limit
) as payout
JOIN hive_posts_view hp ON hp.id = payout.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
ORDER BY payout.all_payout DESC, payout.id DESC
LIMIT _limit;
END
......@@ -258,7 +258,7 @@ BEGIN
JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
WHERE hs.account_id = __account_id AND NOT hp.is_paidout AND hp.payout_at BETWEEN __head_block_time + interval '12 hours' AND __head_block_time + interval '36 hours'
AND ( __post_id = 0 OR ( hp.payout + hp.pending_payout ) < __payout_limit OR ( ( hp.payout + hp.pending_payout ) = __payout_limit AND hp.id < __post_id ) )
AND (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __account_id AND muted_id = hp.author_id))
ORDER BY ( hp.payout + hp.pending_payout ) DESC, hp.id DESC
LIMIT _limit;
END
......@@ -323,7 +323,7 @@ BEGIN
JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
WHERE hs.account_id = __account_id AND NOT hp.is_paidout AND hp.promoted > 0
AND ( __post_id = 0 OR hp.promoted < __promoted_limit OR ( hp.promoted = __promoted_limit AND hp.id < __post_id ) )
AND (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __account_id AND muted_id = hp.author_id))
ORDER BY hp.promoted DESC, hp.id DESC
LIMIT _limit;
END
......@@ -395,11 +395,11 @@ BEGIN
WHERE
hs.account_id = __account_id AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0
AND ( __post_id = 0 OR hp1.sc_trend < __trending_limit OR ( hp1.sc_trend = __trending_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __account_id AND muted_id = hp1.author_id))
ORDER BY hp1.sc_trend DESC, hp1.id DESC
LIMIT _limit
) trending
JOIN hive_posts_view hp ON trending.id = hp.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
ORDER BY trending.sc_trend DESC, trending.id DESC
LIMIT _limit;
END
......@@ -465,7 +465,6 @@ BEGIN
JOIN hive_accounts_view ha ON ha.id = hp.author_id
WHERE hs.account_id = __account_id AND NOT hp.is_paidout AND ha.is_grayed AND ( hp.payout + hp.pending_payout ) > 0
AND ( __post_id = 0 OR ( hp.payout + hp.pending_payout ) < __payout_limit OR ( ( hp.payout + hp.pending_payout ) = __payout_limit AND hp.id < __post_id ) )
AND (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE True END)
ORDER BY ( hp.payout + hp.pending_payout ) DESC, hp.id DESC
LIMIT _limit;
END
......
......@@ -6,9 +6,11 @@ $function$
DECLARE
__post_id INT;
__hive_tag INT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__hive_tag = find_tag_id( _tag, True );
__observer_id = find_account_id(_observer, False);
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -57,11 +59,11 @@ BEGIN
JOIN hive_accounts_view ha ON hp1.author_id = ha.id
WHERE hpt.tag_id = __hive_tag AND hp1.counter_deleted = 0 AND hp1.depth = 0 AND NOT ha.is_grayed AND ( __post_id = 0 OR hp1.id < __post_id )
--ORDER BY hp1.id + 0 DESC -- this workaround helped the query to better choose indexes, but after some time it started to significally slow down
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY hp1.id DESC
LIMIT _limit
) as created
JOIN hive_posts_view hp ON hp.id = created.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY created.id DESC
LIMIT _limit;
END
......@@ -77,12 +79,14 @@ DECLARE
__post_id INT;
__hot_limit FLOAT;
__hive_tag INT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
IF __post_id <> 0 THEN
SELECT hp.sc_hot INTO __hot_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__hive_tag = find_tag_id( _tag, True );
__observer_id = find_account_id(_observer, False);
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -131,11 +135,11 @@ BEGIN
JOIN hive_posts hp1 ON hp1.id = hpt.post_id
WHERE hpt.tag_id = __hive_tag AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0
AND ( __post_id = 0 OR hp1.sc_hot < __hot_limit OR ( hp1.sc_hot = __hot_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY hp1.sc_hot DESC, hp1.id DESC
LIMIT _limit
) as hot
JOIN hive_posts_view hp ON hp.id = hot.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY hot.hot DESC, hot.id DESC
LIMIT _limit;
END
......@@ -210,7 +214,6 @@ BEGIN
LIMIT _limit
) as payout
JOIN hive_posts_view hp ON hp.id = payout.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY payout.all_payout DESC, payout.id DESC
LIMIT _limit;
END
......@@ -226,12 +229,14 @@ DECLARE
__post_id INT;
__payout_limit hive_posts.payout%TYPE;
__hive_category INT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
IF __post_id <> 0 THEN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__hive_category = find_category_id( _category, True );
__observer_id = find_account_id(_observer, False);
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -279,11 +284,11 @@ BEGIN
hive_posts hp1
WHERE hp1.category_id = __hive_category AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth > 0
AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY ( hp1.payout + hp1.pending_payout ) DESC, hp1.id DESC
LIMIT _limit
) as payout
JOIN hive_posts_view hp ON hp.id = payout.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY payout.all_payout DESC, payout.id DESC
LIMIT _limit;
END
......@@ -300,6 +305,7 @@ DECLARE
__payout_limit hive_posts.payout%TYPE;
__head_block_time TIMESTAMP;
__hive_category INT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
IF __post_id <> 0 THEN
......@@ -307,6 +313,7 @@ BEGIN
END IF;
__hive_category = find_category_id( _category, True );
__head_block_time = head_block_time();
__observer_id = find_account_id(_observer, False);
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -355,11 +362,11 @@ BEGIN
WHERE hp1.category_id = __hive_category AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout
AND ( ( NOT _bridge_api AND hp1.depth = 0 ) OR ( _bridge_api AND hp1.payout_at BETWEEN __head_block_time + interval '12 hours' AND __head_block_time + interval '36 hours' ) )
AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY ( hp1.payout + hp1.pending_payout ) DESC, hp1.id DESC
LIMIT _limit
) as payout
JOIN hive_posts_view hp ON hp.id = payout.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY payout.all_payout DESC, payout.id DESC
LIMIT _limit;
END
......@@ -375,12 +382,14 @@ DECLARE
__post_id INT;
__promoted_limit hive_posts.promoted%TYPE;
__hive_tag INT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
IF __post_id <> 0 THEN
SELECT hp.promoted INTO __promoted_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__hive_tag = find_tag_id( _tag, True );
__observer_id = find_account_id(_observer, False);
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -429,11 +438,11 @@ BEGIN
JOIN hive_posts hp1 ON hp1.id = hpt.post_id
WHERE hpt.tag_id = __hive_tag AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.promoted > 0
AND ( __post_id = 0 OR hp1.promoted < __promoted_limit OR ( hp1.promoted = __promoted_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY hp1.promoted DESC, hp1.id DESC
LIMIT _limit
) as promoted
JOIN hive_posts_view hp ON hp.id = promoted.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY promoted.promoted DESC, promoted.id DESC
LIMIT _limit;
END
......@@ -449,12 +458,14 @@ DECLARE
__post_id INT;
__trending_limit FLOAT;
__hive_tag INT;
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
IF __post_id <> 0 THEN
SELECT hp.sc_trend INTO __trending_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__hive_tag = find_tag_id( _tag, True );
__observer_id = find_account_id(_observer, False);
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -503,11 +514,11 @@ BEGIN
JOIN hive_posts hp1 ON hp1.id = hpt.post_id
WHERE hpt.tag_id = __hive_tag AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0
AND ( __post_id = 0 OR hp1.sc_trend < __trending_limit OR ( hp1.sc_trend = __trending_limit AND hp1.id < __post_id ) )
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id))
ORDER BY hp1.sc_trend DESC, hp1.id DESC
LIMIT _limit
) as trends
JOIN hive_posts_view hp ON hp.id = trends.id
WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END)
ORDER BY trends.trend DESC, trends.id DESC
LIMIT _limit;
END
......
......@@ -40,6 +40,7 @@ CREATE TYPE bridge_api_post AS (
);
DROP TYPE IF EXISTS bridge_api_post_reblogs CASCADE;
-- extension of bridge_api_post (same fields/types/order plus extras at the end)
CREATE TYPE bridge_api_post_reblogs AS (
id INTEGER,
author VARCHAR,
......@@ -77,5 +78,49 @@ CREATE TYPE bridge_api_post_reblogs AS (
role_id SMALLINT,
is_pinned BOOLEAN,
curator_payout_value VARCHAR,
is_muted BOOLEAN,
reblogged_by VARCHAR[]
);
DROP TYPE IF EXISTS bridge_api_post_discussion CASCADE;
-- extension of bridge_api_post (same fields/types/order plus extras at the end)
CREATE TYPE bridge_api_post_discussion AS (
id INTEGER,
author VARCHAR,
parent_author VARCHAR,
author_rep BIGINT,
root_title VARCHAR,
beneficiaries JSON,
max_accepted_payout VARCHAR,
percent_hbd INTEGER,
url TEXT,
permlink VARCHAR,
parent_permlink_or_category VARCHAR,
title VARCHAR,
body TEXT,
category VARCHAR,
depth SMALLINT,
promoted DECIMAL(10,3),
payout DECIMAL(10,3),
pending_payout DECIMAL(10,3),
payout_at TIMESTAMP,
is_paidout BOOLEAN,
children INTEGER,
votes INTEGER,
created_at TIMESTAMP,
updated_at TIMESTAMP,
rshares NUMERIC,
abs_rshares NUMERIC,
json TEXT,
is_hidden BOOLEAN,
is_grayed BOOLEAN,
total_votes BIGINT,
sc_trend FLOAT4,
role_title VARCHAR,
community_title VARCHAR,
role_id SMALLINT,
is_pinned BOOLEAN,
curator_payout_value VARCHAR,
is_muted BOOLEAN,
parent_id INTEGER
);
\ No newline at end of file
......@@ -4,7 +4,8 @@ CREATE FUNCTION bridge_get_relationship_between_accounts( in _account1 VARCHAR,
RETURNS TABLE(
state hive_follows.state%TYPE,
blacklisted hive_follows.blacklisted%TYPE,
follow_blacklists hive_follows.follow_blacklists%TYPE
follow_blacklists hive_follows.follow_blacklists%TYPE,
follow_muted hive_follows.follow_muted%TYPE
)
AS
$function$
......@@ -17,7 +18,8 @@ BEGIN
RETURN QUERY SELECT
hf.state,
hf.blacklisted,
hf.follow_blacklists
hf.follow_blacklists,
hf.follow_muted
FROM
hive_follows hf
WHERE
......
......@@ -2,18 +2,16 @@ DROP TYPE IF EXISTS AccountReputation CASCADE;
CREATE TYPE AccountReputation AS (id int, reputation bigint, is_implicit boolean, changed boolean);
DROP FUNCTION IF EXISTS public.calculate_account_reputations;
DROP FUNCTION IF EXISTS calculate_account_reputations;
CREATE OR REPLACE FUNCTION public.calculate_account_reputations(
--- Massive version of account reputation calculation.
CREATE OR REPLACE FUNCTION calculate_account_reputations(
_first_block_num integer,
_last_block_num integer,
_tracked_account character varying DEFAULT NULL::character varying)
RETURNS SETOF accountreputation
LANGUAGE 'plpgsql'
COST 100
STABLE
ROWS 1000
AS $BODY$
DECLARE
__vote_data RECORD;
......@@ -110,6 +108,144 @@ END
$BODY$
;
DROP FUNCTION IF EXISTS calculate_account_reputations_for_block;
CREATE OR REPLACE FUNCTION calculate_account_reputations_for_block(_block_num INT, _tracked_account VARCHAR DEFAULT NULL::VARCHAR)
RETURNS SETOF accountreputation
LANGUAGE 'plpgsql'
VOLATILE
AS $BODY$
DECLARE
__vote_data RECORD;
__author_rep bigint;
__new_author_rep bigint;
__voter_rep bigint;
__implicit_voter_rep boolean;
__implicit_author_rep boolean;
__author_rep_changed boolean := false;
__rshares bigint;
__prev_rshares bigint;
__rep_delta bigint;
__prev_rep_delta bigint;
__traced_author int;
__account_name varchar;
BEGIN
CREATE UNLOGGED TABLE IF NOT EXISTS __new_reputation_data
(
id integer,
author_id integer,
voter_id integer,
rshares bigint,
prev_rshares bigint
);
TRUNCATE TABLE __new_reputation_data;
INSERT INTO __new_reputation_data
SELECT rd.id, rd.author_id, rd.voter_id, rd.rshares,
COALESCE((SELECT prd.rshares
FROM hive_reputation_data prd
WHERE prd.author_id = rd.author_id AND prd.voter_id = rd.voter_id
AND prd.permlink = rd.permlink AND prd.id < rd.id
ORDER BY prd.id DESC LIMIT 1), 0) AS prev_rshares
FROM hive_reputation_data rd
WHERE rd.block_num = _block_num
ORDER BY rd.id
;
CREATE UNLOGGED TABLE IF NOT EXISTS __tmp_accounts
(
id integer,
reputation bigint,
is_implicit boolean,
changed boolean
);
TRUNCATE TABLE __tmp_accounts;
INSERT INTO __tmp_accounts
SELECT ha.id, ha.reputation, ha.is_implicit, false AS changed
FROM __new_reputation_data rd
JOIN hive_accounts ha on rd.author_id = ha.id
UNION
SELECT hv.id, hv.reputation, hv.is_implicit, false as changed
FROM __new_reputation_data rd
JOIN hive_accounts hv on rd.voter_id = hv.id
;
-- SELECT COALESCE((SELECT ha.id FROM hive_accounts ha WHERE ha.name = _tracked_account), 0) INTO __traced_author;
FOR __vote_data IN
SELECT rd.id, rd.author_id, rd.voter_id, rd.rshares, rd.prev_rshares
FROM __new_reputation_data rd
ORDER BY rd.id
LOOP
SELECT INTO __voter_rep, __implicit_voter_rep ha.reputation, ha.is_implicit
FROM __tmp_accounts ha where ha.id = __vote_data.voter_id;
SELECT INTO __author_rep, __implicit_author_rep ha.reputation, ha.is_implicit
FROM __tmp_accounts ha where ha.id = __vote_data.author_id;
/* IF __vote_data.author_id = __traced_author THEN
raise notice 'Processing vote <%> rshares: %, prev_rshares: %', __vote_data.id, __vote_data.rshares, __vote_data.prev_rshares;
select ha.name into __account_name from hive_accounts ha where ha.id = __vote_data.voter_id;
raise notice 'Voter `%` (%) reputation: %', __account_name, __vote_data.voter_id, __voter_rep;
END IF;
*/
CONTINUE WHEN __voter_rep < 0;
__rshares := __vote_data.rshares;
__prev_rshares := __vote_data.prev_rshares;
__prev_rep_delta := (__prev_rshares >> 6)::bigint;
IF NOT __implicit_author_rep AND --- Author must have set explicit reputation to allow its correction
(__prev_rshares > 0 OR
--- Voter must have explicitly set reputation to match hived old conditions
(__prev_rshares < 0 AND NOT __implicit_voter_rep AND __voter_rep > __author_rep - __prev_rep_delta)) THEN
__author_rep := __author_rep - __prev_rep_delta;
__implicit_author_rep := __author_rep = 0;
__author_rep_changed = true;
if __vote_data.author_id = __vote_data.voter_id THEN
__implicit_voter_rep := __implicit_author_rep;
__voter_rep := __author_rep;
end if;
/* IF __vote_data.author_id = __traced_author THEN
raise notice 'Corrected author_rep by prev_rep_delta: % to have reputation: %', __prev_rep_delta, __author_rep;
END IF;
*/
END IF;
IF __rshares > 0 OR
(__rshares < 0 AND NOT __implicit_voter_rep AND __voter_rep > __author_rep) THEN
__rep_delta := (__rshares >> 6)::bigint;
__new_author_rep = __author_rep + __rep_delta;
__author_rep_changed = true;
UPDATE __tmp_accounts
SET reputation = __new_author_rep,
is_implicit = False,
changed = true
WHERE id = __vote_data.author_id;
/* IF __vote_data.author_id = __traced_author THEN
raise notice 'Changing account: <%> reputation from % to %', __vote_data.author_id, __author_rep, __new_author_rep;
END IF;
*/
ELSE
/* IF __vote_data.author_id = __traced_author THEN
raise notice 'Ignoring reputation change due to unmet conditions... Author_rep: %, Voter_rep: %', __author_rep, __voter_rep;
END IF;
*/
END IF;
END LOOP;
RETURN QUERY SELECT id, reputation, is_implicit, Changed
FROM __tmp_accounts
WHERE Reputation IS NOT NULL AND Changed
;
END
$BODY$
;
DROP FUNCTION IF EXISTS public.update_account_reputations;
CREATE OR REPLACE FUNCTION public.update_account_reputations(
......@@ -127,6 +263,14 @@ BEGIN
(
SELECT p.id as account_id, p.reputation, p.is_implicit
FROM calculate_account_reputations(_first_block_num, _last_block_num) p
WHERE _first_block_num IS NULL OR _last_block_num IS NULL OR _first_block_num != _last_block_num
UNION ALL
SELECT p.id as account_id, p.reputation, p.is_implicit
FROM calculate_account_reputations_for_block(_first_block_num) p
WHERE _first_block_num IS NOT NULL AND _last_block_num IS NOT NULL AND _first_block_num = _last_block_num
) ds
WHERE urs.id = ds.account_id AND (urs.reputation != ds.reputation OR urs.is_implicit != ds.is_implicit)
;
......
......@@ -15,12 +15,14 @@ for sql in postgres_handle_view_changes.sql \
hive_posts_view.sql \
hive_votes_view.sql \
hive_muted_accounts_view.sql \
hive_muted_accounts_by_id_view.sql \
hive_post_operations.sql \
head_block_time.sql \
update_feed_cache.sql \
payout_stats_view.sql \
update_hive_posts_mentions.sql \
find_tag_id.sql \
mutes.sql \
bridge_get_ranked_post_type.sql \
bridge_get_ranked_post_for_communities.sql \
bridge_get_ranked_post_for_observer_communities.sql \
......@@ -64,10 +66,10 @@ for sql in postgres_handle_view_changes.sql \
do
echo Executing psql -U $1 -d $2 -f $sql
time psql -1 -v "ON_ERROR_STOP=1" -U $1 -d $2 -c '\timing' -f $sql 2>&1 | tee -a -i upgrade.log
time psql -a -1 -v "ON_ERROR_STOP=1" -U $1 -d $2 -c '\timing' -f $sql 2>&1 | tee -a -i upgrade.log
echo $?
done
time psql -v "ON_ERROR_STOP=1" -U $1 -d $2 -c '\timing' -f upgrade/upgrade_runtime_migration.sql 2>&1 | tee -a -i upgrade.log
time psql -a -v "ON_ERROR_STOP=1" -U $1 -d $2 -c '\timing' -f upgrade/upgrade_runtime_migration.sql 2>&1 | tee -a -i upgrade.log
DROP VIEW IF EXISTS muted_accounts_by_id_view CASCADE;
CREATE OR REPLACE VIEW muted_accounts_by_id_view AS
SELECT observer_accounts.id AS observer_id,
following_accounts.id AS muted_id
FROM ((hive_follows
JOIN hive_accounts following_accounts ON ((hive_follows.following = following_accounts.id)))
JOIN hive_accounts observer_accounts ON ((hive_follows.follower = observer_accounts.id)))
WHERE (hive_follows.state = 2)
UNION
SELECT observer_accounts.id AS observer_id,
following_accounts.id AS muted_id
FROM (((hive_follows hive_follows_direct
JOIN hive_follows hive_follows_indirect ON ((hive_follows_direct.following = hive_follows_indirect.follower)))
JOIN hive_accounts following_accounts ON ((hive_follows_indirect.following = following_accounts.id)))
JOIN hive_accounts observer_accounts ON ((hive_follows_direct.follower = observer_accounts.id)))
WHERE (hive_follows_direct.follow_muted AND (hive_follows_indirect.state = 2));
\ No newline at end of file
DROP FUNCTION IF EXISTS mutes_get_blacklisted_for_observer;
CREATE FUNCTION mutes_get_blacklisted_for_observer( in _observer VARCHAR, in _flags INTEGER )
RETURNS TABLE(
account hive_accounts.name%TYPE,
source VARCHAR,
is_blacklisted BOOLEAN -- False means muted
)
AS
$function$
DECLARE
__observer_id INT;
BEGIN
__observer_id = find_account_id( _observer, True );
IF (_flags & 1)::BOOLEAN THEN
RETURN QUERY SELECT -- mutes_get_blacklisted_for_observer (local observer blacklist)
ha.name AS account,
_observer AS source,
True
FROM
hive_follows hf
JOIN hive_accounts ha ON ha.id = hf.following
WHERE
hf.follower = __observer_id AND hf.blacklisted
ORDER BY account, source;
END IF;
IF (_flags & 2)::BOOLEAN THEN
RETURN QUERY SELECT -- mutes_get_blacklisted_for_observer (indirect observer blacklists)
ha_i.name AS account,
ha.name AS source,
True
FROM
hive_follows hf
JOIN hive_follows hf_i ON hf_i.follower = hf.following
JOIN hive_accounts ha_i ON ha_i.id = hf_i.following
JOIN hive_accounts ha ON ha.id = hf.following
WHERE
hf.follower = __observer_id AND hf.follow_blacklists AND hf_i.blacklisted
ORDER BY account, source;
END IF;
IF (_flags & 4)::BOOLEAN THEN
RETURN QUERY SELECT-- mutes_get_blacklisted_for_observer (local observer mute list)
ha.name AS account,
_observer AS source,
False
FROM
hive_follows hf
JOIN hive_accounts ha ON ha.id = hf.following
WHERE
hf.follower = __observer_id AND hf.state = 2
ORDER BY account, source;
END IF;
IF (_flags & 8)::BOOLEAN THEN
RETURN QUERY SELECT-- mutes_get_blacklisted_for_observer (indirect observer mute list)
ha_i.name AS account,
ha.name AS source,
False
FROM
hive_follows hf
JOIN hive_follows hf_i ON hf_i.follower = hf.following
JOIN hive_accounts ha_i ON ha_i.id = hf_i.following
JOIN hive_accounts ha ON ha.id = hf.following
WHERE
hf.follower = __observer_id AND hf.follow_muted AND hf_i.state = 2
ORDER BY account, source;
END IF;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS mutes_get_blacklists_for_observer;
CREATE FUNCTION mutes_get_blacklists_for_observer( in _observer VARCHAR, in _follow_blacklist BOOLEAN, in _follow_muted BOOLEAN )
RETURNS TABLE(
list hive_accounts.name%TYPE,
is_blacklist BOOLEAN -- False means mute list
)
AS
$function$
DECLARE
__observer_id INT;
BEGIN
__observer_id = find_account_id( _observer, True );
IF _follow_blacklist THEN
RETURN QUERY SELECT -- mutes_get_blacklists_for_observer (observer blacklists)
ha.name AS list,
True
FROM
hive_follows hf
JOIN hive_accounts ha ON ha.id = hf.following
WHERE
hf.follower = __observer_id AND hf.follow_blacklists
ORDER BY list;
END IF;
IF _follow_muted THEN
RETURN QUERY SELECT -- mutes_get_blacklists_for_observer (observer mute lists)
ha.name AS list,
False
FROM
hive_follows hf
JOIN hive_accounts ha ON ha.id = hf.following
WHERE
hf.follower = __observer_id AND hf.follow_muted
ORDER BY list;
END IF;
END
$function$
language plpgsql STABLE;
......@@ -125,6 +125,26 @@ END
$BODY$;
COMMIT;
START TRANSACTION;
DO
$BODY$
BEGIN
SET work_mem='2GB';
IF NOT EXISTS(SELECT * FROM hive_db_patch_level WHERE patched_to_revision = 'cce7fe54a2242b7a80354ee7e50e5b3275a2b039') THEN
RAISE NOTICE 'Performing reputation livesync recalculation...';
--- reputations have to be recalculated from scratch.
UPDATE hive_accounts SET reputation = 0, is_implicit = True;
PERFORM update_account_reputations(NULL, NULL);
ELSE
RAISE NOTICE 'Skipping reputation livesync recalculation...';
END IF;
END
$BODY$;
COMMIT;
START TRANSACTION;
TRUNCATE TABLE hive_db_data_migration;
......@@ -167,6 +187,7 @@ values
,(now(), '2a274e586454968a4f298a855a7e60394ed90bde') -- get_number_of_unread_notifications speedup https://gitlab.syncad.com/hive/hivemind/-/merge_requests/348/diffs
,(now(), '431fdaead7dcd69e4d2a45e7ce8a3186b8075515') -- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/367
,(now(), 'cc7bb174d40fe1a0e2221d5d7e1c332c344dca34') -- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/372
,(now(), 'cce7fe54a2242b7a80354ee7e50e5b3275a2b039') -- reputation calc at LIVE sync.
) ds (patch_date, patch_revision)
where not exists (select null from hive_db_patch_level hpl where hpl.patched_to_revision = ds.patch_revision);
......
......@@ -219,7 +219,8 @@ $BODY$
;
DROP INDEX IF EXISTS hive_posts_created_at_idx;
CREATE INDEX IF NOT EXISTS hive_posts_created_at_author_id_idx ON hive_posts (created_at, author_id);
-- skip it since it is dropped below.
-- CREATE INDEX IF NOT EXISTS hive_posts_created_at_author_id_idx ON hive_posts (created_at, author_id);
CREATE INDEX IF NOT EXISTS hive_posts_block_num_created_idx ON hive_posts (block_num_created);
......@@ -283,13 +284,17 @@ DROP INDEX IF EXISTS hive_posts_is_paidout_idx;
DROP INDEX IF EXISTS hive_posts_sc_trend_id_idx;
DROP INDEX IF EXISTS hive_posts_sc_hot_id_idx;
CREATE INDEX IF NOT EXISTS hive_posts_sc_trend_id_is_paidout_idx ON hive_posts(sc_trend, id, is_paidout );
CREATE INDEX IF NOT EXISTS hive_posts_sc_hot_id_is_paidout_idx ON hive_posts(sc_hot, id, is_paidout );
--- Commented out as it is dropped below.
--- CREATE INDEX IF NOT EXISTS hive_posts_sc_trend_id_is_paidout_idx ON hive_posts(sc_trend, id, is_paidout );
--- Commented out as it is dropped below.
--- CREATE INDEX IF NOT EXISTS hive_posts_sc_hot_id_is_paidout_idx ON hive_posts(sc_hot, id, is_paidout );
--- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/302
DROP INDEX IF EXISTS hive_posts_payout_plus_pending_payout_id;
CREATE INDEX IF NOT EXISTS hive_posts_payout_plus_pending_payout_id_is_paidout_idx ON hive_posts ((payout+pending_payout), id, is_paidout);
--- Commented out as dropped below.
--- CREATE INDEX IF NOT EXISTS hive_posts_payout_plus_pending_payout_id_is_paidout_idx ON hive_posts ((payout+pending_payout), id, is_paidout);
--- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/310
......
......@@ -443,7 +443,7 @@ class Blocks:
"SELECT update_hive_posts_mentions({}, {})".format(first_block, last_block),
"SELECT update_notification_cache({}, {}, {})".format(first_block, last_block, is_hour_action),
"SELECT update_follow_count({}, {})".format(first_block, last_block),
#,"SELECT update_account_reputations({}, {})".format(first_block, last_block)
"SELECT update_account_reputations({}, {})".format(first_block, last_block)
]
for query in queries:
......
......@@ -55,16 +55,16 @@ async def get_post(context, author, permlink, observer=None):
valid_account(observer, allow_empty=True)
valid_permlink(permlink)
blacklists_for_user = None
if observer and context:
blacklists_for_user = await Mutes.get_blacklists_for_observer(observer, context)
blacklisted_for_user = None
if observer:
blacklisted_for_user = await Mutes.get_blacklisted_for_observer(observer, context)
sql = "SELECT * FROM bridge_get_post( (:author)::VARCHAR, (:permlink)::VARCHAR )"
result = await db.query_all(sql, author=author, permlink=permlink)
post = _bridge_post_object(result[0])
post['active_votes'] = await find_votes_impl(db, author, permlink, VotesPresentation.BridgeApi)
post = append_statistics_to_post(post, result[0], False, blacklists_for_user)
post = append_statistics_to_post(post, result[0], False, blacklisted_for_user)
return post
@return_error_info
......@@ -103,7 +103,7 @@ async def _get_ranked_posts_for_observer_communities( db, sort:str, start_author
assert False, "Unknown sort order"
@return_error_info
async def _get_ranked_posts_for_communities( db, sort:str, community, start_author:str, start_permlink:str, limit, observer:str=None):
async def _get_ranked_posts_for_communities( db, sort:str, community, start_author:str, start_permlink:str, limit, observer:str ):
async def execute_community_query(db, sql, limit):
return await db.query_all(sql, community=community, author=start_author, permlink=start_permlink, limit=limit, observer=observer )
......@@ -151,72 +151,72 @@ async def _get_ranked_posts_for_communities( db, sort:str, community, start_auth
@return_error_info
async def _get_ranked_posts_for_tag( db, sort:str, tag, start_author:str, start_permlink:str, limit, observer:str=None):
async def execute_tags_query(db, sql, limit):
async def _get_ranked_posts_for_tag( db, sort:str, tag, start_author:str, start_permlink:str, limit, observer:str ):
async def execute_tags_query(db, sql):
return await db.query_all(sql, tag=tag, author=start_author, permlink=start_permlink, limit=limit, observer=observer )
if sort == 'hot':
sql = "SELECT * FROM bridge_get_ranked_post_by_hot_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
return await execute_tags_query(db, sql)
if sort == 'promoted':
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
return await execute_tags_query(db, sql)
if sort == 'payout':
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_for_category( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, True, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
return await execute_tags_query(db, sql)
if sort == 'payout_comments':
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_comments_for_category( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
return await execute_tags_query(db, sql)
if sort == 'muted':
sql = "SELECT * FROM bridge_get_ranked_post_by_muted_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
return await execute_tags_query(db, sql)
if sort == 'trending':
sql = "SELECT * FROM bridge_get_ranked_post_by_trends_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
return await execute_tags_query(db, sql)
if sort == 'created':
sql = "SELECT * FROM bridge_get_ranked_post_by_created_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
return await execute_tags_query(db, sql)
assert False, "Unknown sort order"
@return_error_info
async def _get_ranked_posts_for_all( db, sort:str, start_author:str, start_permlink:str, limit, observer:str=None):
async def execute_query(db, sql, limit, observer=None):
async def _get_ranked_posts_for_all( db, sort:str, start_author:str, start_permlink:str, limit, observer:str ):
async def execute_query(db, sql):
return await db.query_all(sql, author=start_author, permlink=start_permlink, limit=limit, observer=observer )
if sort == 'trending':
sql = "SELECT * FROM bridge_get_ranked_post_by_trends( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit)
return await execute_query(db, sql)
if sort == 'created':
sql = "SELECT * FROM bridge_get_ranked_post_by_created( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit, observer)
return await execute_query(db, sql)
if sort == 'hot':
sql = "SELECT * FROM bridge_get_ranked_post_by_hot( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit)
return await execute_query(db, sql)
if sort == 'promoted':
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit)
return await execute_query(db, sql)
if sort == 'payout':
sql = "SELECT * FROM bridge_get_ranked_post_by_payout( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, True, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit)
return await execute_query(db, sql)
if sort == 'payout_comments':
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_comments( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit)
return await execute_query(db, sql)
if sort == 'muted':
sql = "SELECT * FROM bridge_get_ranked_post_by_muted( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit)
return await execute_query(db, sql)
assert False, "Unknown sort order"
......@@ -230,14 +230,14 @@ async def get_ranked_posts(context, sort:str, start_author:str='', start_permlin
db = context['db']
async def process_query_results( sql_result ):
blacklists_for_user = None
blacklisted_for_user = None
if observer:
blacklists_for_user = await Mutes.get_blacklists_for_observer(observer, context)
blacklisted_for_user = await Mutes.get_blacklisted_for_observer(observer, context)
posts = []
for row in sql_result:
post = _bridge_post_object(row)
post['active_votes'] = await find_votes_impl(db, row['author'], row['permlink'], VotesPresentation.BridgeApi)
post = append_statistics_to_post(post, row, row['is_pinned'], blacklists_for_user)
post = append_statistics_to_post(post, row, row['is_pinned'], blacklisted_for_user)
posts.append(post)
return posts
......@@ -295,12 +295,12 @@ async def get_account_posts(context, sort:str, account:str, start_author:str='',
sql_result = await db.query_all(sql, account=account, author=start_author, permlink=start_permlink, limit=limit )
posts = []
blacklists_for_user = None
blacklisted_for_user = None
if observer and account_posts:
# it looks like the opposite would make more sense, that is, to handle observer for 'blog', 'feed' and 'replies',
# since that's when posts can come from various authors, some blacklisted and some not, but original version
# ignored it (only) in those cases
blacklists_for_user = await Mutes.get_blacklists_for_observer(observer, context)
blacklisted_for_user = await Mutes.get_blacklisted_for_observer(observer, context)
for row in sql_result:
post = _bridge_post_object(row)
......@@ -316,7 +316,7 @@ async def get_account_posts(context, sort:str, account:str, start_author:str='',
reblogged_by_list.sort()
post['reblogged_by'] = reblogged_by_list
post = append_statistics_to_post(post, row, False if account_posts else row['is_pinned'], blacklists_for_user, not account_posts)
post = append_statistics_to_post(post, row, False if account_posts else row['is_pinned'], blacklisted_for_user)
posts.append(post)
return posts
......@@ -334,8 +334,9 @@ async def get_relationship_between_accounts(context, account1, account2, observe
result = {
'follows': False,
'ignores': False,
'is_blacklisted': False,
'follows_blacklists': False
'blacklists': False,
'follows_blacklists': False,
'follows_muted': False
}
for row in sql_result:
......@@ -346,63 +347,45 @@ async def get_relationship_between_accounts(context, account1, account2, observe
result['ignores'] = True
if row['blacklisted']:
result['is_blacklisted'] = True
result['blacklists'] = True
if row['follow_blacklists']:
result['follows_blacklists'] = True
if row['follow_muted']:
result['follows_muted'] = True
return result
@return_error_info
async def does_user_follow_any_lists(context, observer):
follows_blacklists = await get_follow_list(context, observer, 'follow_blacklist')
follows_muted = await get_follow_list(context, observer, 'follow_muted')
""" Tells if given observer follows any blacklist or mute list """
blacklists_for_user = await Mutes.get_blacklists_for_observer(observer, context)
if len(follows_blacklists) == 0 and len(follows_muted) == 0:
if len(blacklists_for_user) == 0:
return False
else:
return True
@return_error_info
async def get_follow_list(context, observer, follow_type='blacklisted'):
db = context['db']
valid_account(observer)
valid_types = ['blacklisted', 'follow_blacklist', 'muted', 'follow_muted']
assert follow_type in valid_types, 'invalid follow_type'
account_data = await get_profile(context, observer)
metadata = account_data["metadata"]["profile"]
blacklist_description = metadata["blacklist_description"] if "blacklist_description" in metadata else ''
muted_list_description = metadata["muted_list_description"] if "muted_list_description" in metadata else ''
""" For given observer gives directly blacklisted/muted accounts or
list of blacklists/mute lists followed by observer
"""
observer = valid_account(observer)
valid_types = dict(blacklisted=1, follow_blacklist=2, muted=4, follow_muted=8)
assert follow_type in valid_types, "Unsupported follow_type, valid values: {}".format(", ".join(valid_types.keys()))
results = []
if follow_type == 'follow_blacklist':
sql = """select hive_accounts.name
from hive_accounts join hive_follows on (hive_accounts.id = hive_follows.following) where
hive_follows.follower = (select id from hive_accounts where name = :observer) and follow_blacklists"""
sql_result = await db.query_all(sql, observer=observer)
for row in sql_result:
row_result = {'name': row['name'], 'blacklist_description': blacklist_description, 'muted_list_description': muted_list_description}
results.append(row_result)
return results
elif follow_type == 'follow_muted':
sql = """select hive_accounts.name,
from hive_accounts join hive_follows on (hive_accounts.id = hive_follows.following) where
hive_follows.follower = (select id from hive_accounts where name = :observer) and follow_muted"""
sql_result = await db.query_all(sql, observer=observer)
for row in sql_result:
row_result = {'name': row['name'], 'blacklist_description': blacklist_description, 'muted_list_description': muted_list_description}
results.append(row_result)
return results
if follow_type == 'follow_blacklist' or follow_type == 'follow_muted':
blacklists_for_user = await Mutes.get_blacklists_for_observer(observer, context, follow_type == 'follow_blacklist', follow_type == 'follow_muted')
for row in blacklists_for_user:
list_data = await get_profile(context, row['list'])
metadata = list_data["metadata"]["profile"]
blacklist_description = metadata["blacklist_description"] if "blacklist_description" in metadata else ''
muted_list_description = metadata["muted_list_description"] if "muted_list_description" in metadata else ''
results.append({'name': row['list'], 'blacklist_description': blacklist_description, 'muted_list_description': muted_list_description})
else: # blacklisted or muted
blacklisted_for_user = await Mutes.get_blacklisted_for_observer(observer, context, valid_types[follow_type])
for account in blacklisted_for_user.keys():
results.append({'name': account, 'blacklist_description': '', 'muted_list_description': ''})
blacklists_for_user = await Mutes.get_blacklists_for_observer(observer, context)
if follow_type == 'blacklisted':
results.extend([{'name': account, 'blacklist_description':'', 'muted_list_description':''} for account, sources in blacklists_for_user.items() if 'my_blacklist' in sources])
elif follow_type == 'follow_blacklist':
results.extend([{'name': account, 'blacklist_description':'', 'muted_list_description':''} for account, sources in blacklists_for_user.items() if 'my_followed_blacklists' in sources])
elif follow_type == 'muted':
results.extend([{'name': account, 'blacklist_description':'', 'muted_list_description':''} for account, sources in blacklists_for_user.items() if 'my_muted' in sources])
elif follow_type == 'follow_muted':
results.extend([{'name': account, 'blacklist_description':'', 'muted_list_description':''} for account, sources in blacklists_for_user.items() if 'my_followed_mutes' in sources])
return results
......@@ -15,15 +15,16 @@ log = logging.getLogger(__name__)
# pylint: disable=too-many-lines
def append_statistics_to_post(post, row, is_pinned, blacklists_for_user=[], override_gray=False):
def append_statistics_to_post(post, row, is_pinned, blacklisted_for_user={}):
""" apply information such as blacklists and community names/roles to a given post """
post['blacklists'] = []
if blacklists_for_user and row['author'] in blacklists_for_user:
blacklists = blacklists_for_user[row['author']]
for blacklist in blacklists:
post['blacklists'].append(blacklist)
reputation = row['author_rep']
if blacklisted_for_user and row['author'] in blacklisted_for_user:
blacklists = blacklisted_for_user[row['author']]
post['blacklists'].extend(blacklists[0])
for mute_list in blacklists[1]:
post['blacklists'].append(mute_list + ' (mute list)')
reputation = post['author_reputation']
if reputation < 1:
post['blacklists'].append('reputation-0')
elif reputation == 1:
......@@ -39,9 +40,7 @@ def append_statistics_to_post(post, row, is_pinned, blacklists_for_user=[], over
post['author_role'] = 'guest'
post['author_title'] = ''
post['stats']['gray'] = row['is_grayed']
if 'is_muted' in row and row['is_muted']:
post['stats']['gray'] = True
post['stats']['gray'] = row['is_grayed'] or row['is_muted']
if is_pinned:
post['stats']['is_pinned'] = True
return post
......
......@@ -22,9 +22,9 @@ async def get_discussion(context, author, permlink, observer=None):
author = valid_account(author)
permlink = valid_permlink(permlink)
blacklists_for_user = None
blacklisted_for_user = None
if observer:
blacklists_for_user = await Mutes.get_blacklists_for_observer(observer, context)
blacklisted_for_user = await Mutes.get_blacklisted_for_observer(observer, context)
sql = "SELECT * FROM get_discussion(:author,:permlink,:observer)"
rows = await db.query_all(sql, author=author, permlink=permlink, observer=observer)
......@@ -34,7 +34,7 @@ async def get_discussion(context, author, permlink, observer=None):
all_posts = {}
root_post = _bridge_post_object(rows[0])
root_post['active_votes'] = await find_votes_impl(db, rows[0]['author'], rows[0]['permlink'], VotesPresentation.BridgeApi)
root_post = append_statistics_to_post(root_post, rows[0], False, blacklists_for_user)
root_post = append_statistics_to_post(root_post, rows[0], False, blacklisted_for_user)
root_post['replies'] = []
all_posts[root_id] = root_post
......@@ -47,7 +47,7 @@ async def get_discussion(context, author, permlink, observer=None):
parent_to_children_id_map[parent_id].append(rows[index]['id'])
post = _bridge_post_object(rows[index])
post['active_votes'] = await find_votes_impl(db, rows[index]['author'], rows[index]['permlink'], VotesPresentation.BridgeApi)
post = append_statistics_to_post(post, rows[index], False, blacklists_for_user)
post = append_statistics_to_post(post, rows[index], False, blacklisted_for_user)
post['replies'] = []
all_posts[post['post_id']] = post
......