mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-29 07:41:20 +00:00
stuff
This commit is contained in:
parent
fb95056b2c
commit
39eb0e8841
2 changed files with 13 additions and 14 deletions
|
@ -215,24 +215,22 @@ BEGIN
|
||||||
AS $$
|
AS $$
|
||||||
BEGIN
|
BEGIN
|
||||||
-- Update aggregates for target, then update aggregates for target's creator
|
-- Update aggregates for target, then update aggregates for target's creator
|
||||||
WITH target_diff (
|
WITH target_diff AS ( UPDATE
|
||||||
creator_id, score
|
%1$s_aggregates
|
||||||
) AS ( UPDATE
|
|
||||||
%1$s_aggregates AS target_aggregates
|
|
||||||
SET
|
SET
|
||||||
score = score + diff.upvotes - diff.downvotes, upvotes = upvotes + diff.upvotes, downvotes = downvotes + diff.downvotes, controversy_rank = controversy_rank ((upvotes + diff.upvotes)::numeric, (downvotes + diff.downvotes)::numeric)
|
(score, upvotes, downvotes, controversy_rank) = (score + diff.upvotes - diff.downvotes, upvotes + diff.upvotes, downvotes + diff.downvotes, controversy_rank ((upvotes + diff.upvotes)::numeric, (downvotes + diff.downvotes)::numeric))
|
||||||
FROM (
|
FROM (
|
||||||
SELECT
|
SELECT
|
||||||
target_id, sum(count_diff) FILTER (WHERE score = 1) AS upvotes, sum(count_diff) FILTER (WHERE score <> 1) AS downvotes FROM r.combine_transition_tables ()
|
%1$s_id, sum(count_diff) FILTER (WHERE score = 1) AS upvotes, sum(count_diff) FILTER (WHERE score <> 1) AS downvotes FROM r.combine_transition_tables ()
|
||||||
GROUP BY target_id) AS diff
|
GROUP BY %1$s_id) AS diff
|
||||||
WHERE
|
WHERE
|
||||||
target_aggregates.comment_id = diff.target_id
|
%1$s_aggregates.%1 $ s_id = diff.%1$s_id
|
||||||
RETURNING
|
RETURNING
|
||||||
%2$s, diff.upvotes - diff.downvotes)
|
%2$s AS creator_id, diff.upvotes - diff.downvotes AS score)
|
||||||
UPDATE
|
UPDATE
|
||||||
person_aggregates
|
person_aggregates
|
||||||
SET
|
SET
|
||||||
%1$s_score = %1$s_score + diff.score FROM (
|
%1$s_score = %1$s_score + diff.sum FROM (
|
||||||
SELECT
|
SELECT
|
||||||
creator_id, sum(score)
|
creator_id, sum(score)
|
||||||
FROM target_diff GROUP BY creator_id) AS diff
|
FROM target_diff GROUP BY creator_id) AS diff
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
export PGDATA="$PWD/dev_pgdata"
|
export PGDATA="$PWD/dev_pgdata"
|
||||||
export PGHOST=$PWD
|
export PGHOST=$PWD
|
||||||
export PGUSER=postgres
|
export PGUSER=postgres
|
||||||
export LEMMY_DATABASE_URL="postgresql://lemmy:password@/lemmy?host=$PWD"
|
export DATABASE_URL="postgresql://lemmy:password@/lemmy?host=$PWD"
|
||||||
|
export LEMMY_DATABASE_URL=$DATABASE_URL
|
||||||
|
export PGDATABASE=lemmy
|
||||||
|
|
||||||
# If cluster exists, stop the server and delete the cluster
|
# If cluster exists, stop the server and delete the cluster
|
||||||
if [ -d $PGDATA ]
|
if [ -d $PGDATA ]
|
||||||
|
@ -21,6 +23,5 @@ initdb --username=postgres --auth=trust --no-instructions
|
||||||
pg_ctl start --options="-c listen_addresses= -c unix_socket_directories=$PWD" > /dev/null
|
pg_ctl start --options="-c listen_addresses= -c unix_socket_directories=$PWD" > /dev/null
|
||||||
|
|
||||||
# Setup database
|
# Setup database
|
||||||
psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;"
|
PGDATABASE=postgres psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;"
|
||||||
psql -c "CREATE DATABASE lemmy WITH OWNER lemmy;"
|
PGDATABASE=postgres psql -c "CREATE DATABASE lemmy WITH OWNER lemmy;"
|
||||||
export PGDATABASE=lemmy
|
|
||||||
|
|
Loading…
Reference in a new issue