Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Commits
2c0b485e
Commit
2c0b485e
authored
4 years ago
by
Dariusz Kędzierski
Browse files
Options
Downloads
Patches
Plain Diff
Fixes and cleanup
parent
23f4a461
No related branches found
No related tags found
5 merge requests
!456
Release candidate v1 24
,
!230
Setup monitoring with pghero
,
!135
Enable postgres monitoring on CI server
,
!16
Dk issue 3 concurrent block query rebase
,
!15
Dk issue 3 concurrent block query
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
hive/db/schema.py
+3
-1
3 additions, 1 deletion
hive/db/schema.py
hive/indexer/posts.py
+16
-14
16 additions, 14 deletions
hive/indexer/posts.py
hive/indexer/votes.py
+33
-3
33 additions, 3 deletions
hive/indexer/votes.py
scripts/update_hivemind_db.sql
+2
-0
2 additions, 0 deletions
scripts/update_hivemind_db.sql
with
54 additions
and
18 deletions
hive/db/schema.py
+
3
−
1
View file @
2c0b485e
...
...
@@ -205,7 +205,9 @@ def build_metadata():
sa
.
Index
(
'
hive_votes_voter_id_idx
'
,
'
voter_id
'
),
sa
.
Index
(
'
hive_votes_author_id_idx
'
,
'
author_id
'
),
sa
.
Index
(
'
hive_votes_permlink_id_idx
'
,
'
permlink_id
'
)
sa
.
Index
(
'
hive_votes_permlink_id_idx
'
,
'
permlink_id
'
),
sa
.
Index
(
'
hive_votes_upvote_idx
'
,
'
vote_percent
'
,
postgresql_where
=
sql_text
(
"
vote_percent > 0
"
)),
sa
.
Index
(
'
hive_votes_downvote_idx
'
,
'
vote_percent
'
,
postgresql_where
=
sql_text
(
"
vote_percent < 0
"
))
)
sa
.
Table
(
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/posts.py
+
16
−
14
View file @
2c0b485e
...
...
@@ -35,8 +35,6 @@ class Posts:
@classmethod
def
find_root
(
cls
,
author
,
permlink
):
"""
Find root for post
"""
print
(
"
A:
"
,
author
,
"
P:
"
,
permlink
)
sql
=
"""
WITH RECURSIVE parent AS
(
SELECT id, parent_id, 1 AS level from hive_posts WHERE id = (SELECT hp.id
...
...
@@ -193,8 +191,6 @@ class Posts:
@classmethod
def
insert
(
cls
,
op
,
date
):
"""
Inserts new post records.
"""
print
(
"
New Post
"
)
# inserting new post
# * Check for permlink, parent_permlink, root_permlink
# * Check for authro, parent_author, root_author
...
...
@@ -290,7 +286,6 @@ class Posts:
@classmethod
def
undelete
(
cls
,
op
,
date
,
pid
):
"""
Re-allocates an existing record flagged as deleted.
"""
print
(
"
Undelete
"
)
# add category to category table
sql
=
"""
...
...
@@ -326,7 +321,6 @@ class Posts:
@classmethod
def
delete
(
cls
,
op
):
"""
Marks a post record as being deleted.
"""
print
(
"
Delete post
"
)
pid
,
depth
=
cls
.
get_id_and_depth
(
op
[
'
author
'
],
op
[
'
permlink
'
])
DB
.
query
(
"
UPDATE hive_posts SET is_deleted =
'
1
'
WHERE id = :id
"
,
id
=
pid
)
...
...
@@ -348,16 +342,24 @@ class Posts:
Here we could also build content diffs, but for now just used
a signal to update cache record.
"""
print
(
"
Update post
"
)
# pylint: disable=unused-argument
post
=
cls
.
_build_post
(
op
,
date
)
# add permlinks to permlink table
for
permlink
in
[
'
permlink
'
,
'
parent_permlink
'
,
'
root_permlink
'
]:
if
permlink
in
op
:
sql
=
"""
INSERT INTO hive_permlink_data (permlink)
VALUES (:permlink)
ON CONFLICT (permlink) DO NOTHING
"""
DB
.
query
(
sql
,
permlink
=
op
[
permlink
])
# add category to category table
if
'
category
'
in
op
:
sql
=
"""
INSERT INTO hive_category_data (category)
VALUES (:category)
ON CONFLICT (category) DO NOTHING
"""
DB
.
query
(
sql
,
category
=
op
[
'
category
'
])
sql
=
"""
INSERT INTO hive_category_data (category)
VALUES (:category)
ON CONFLICT (category) DO NOTHING
"""
DB
.
query
(
sql
,
category
=
post
[
'
category
'
])
sql
=
"""
UPDATE hive_posts
...
...
@@ -375,7 +377,7 @@ class Posts:
parent_permlink_id = (SELECT id FROM hive_permlink_data WHERE permlink = :parent_permlink)
WHERE id = :id
"""
post
=
cls
.
_build_post
(
op
,
date
)
post
[
'
id
'
]
=
pid
DB
.
query
(
sql
,
**
post
)
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/votes.py
+
33
−
3
View file @
2c0b485e
...
...
@@ -30,16 +30,46 @@ class Votes:
"""
Get vote count for given post
"""
sql
=
"""
SELECT
count(hv.id)
count(hv.id)
FROM
hive_votes hv
INNER JOIN hive_accounts ha_a ON (ha_a.id = hv.author_id)
hive_votes hv
INNER JOIN hive_accounts ha_a ON (ha_a.id = hv.author_id)
INNER JOIN hive_permlink_data hpd ON (hpd.id = hv.permlink_id)
WHERE ha_a.name = :author AND hpd.permlink = :permlink
"""
ret
=
DB
.
query_row
(
sql
,
author
=
author
,
permlink
=
permlink
)
return
0
if
ret
is
None
else
int
(
ret
.
count
)
@classmethod
def
get_upvote_count
(
cls
,
author
,
permlink
):
"""
Get vote count for given post
"""
sql
=
"""
SELECT
count(hv.id)
FROM
hive_votes hv
INNER JOIN hive_accounts ha_a ON (ha_a.id = hv.author_id)
INNER JOIN hive_permlink_data hpd ON (hpd.id = hv.permlink_id)
WHERE ha_a.name = :author AND hpd.permlink = :permlink AND vote_percent > 0
"""
ret
=
DB
.
query_row
(
sql
,
author
=
author
,
permlink
=
permlink
)
return
0
if
ret
is
None
else
int
(
ret
.
count
)
@classmethod
def
get_downvote_count
(
cls
,
author
,
permlink
):
"""
Get vote count for given post
"""
sql
=
"""
SELECT
count(hv.id)
FROM
hive_votes hv
INNER JOIN hive_accounts ha_a ON (ha_a.id = hv.author_id)
INNER JOIN hive_permlink_data hpd ON (hpd.id = hv.permlink_id)
WHERE ha_a.name = :author AND hpd.permlink = :permlink AND vote_percent < 0
"""
ret
=
DB
.
query_row
(
sql
,
author
=
author
,
permlink
=
permlink
)
return
0
if
ret
is
None
else
int
(
ret
.
count
)
@classmethod
def
vote_op
(
cls
,
vop
,
date
):
"""
Process vote_operation
"""
...
...
This diff is collapsed.
Click to expand it.
scripts/update_hivemind_db.sql
+
2
−
0
View file @
2c0b485e
...
...
@@ -170,6 +170,8 @@ CREATE TABLE IF NOT EXISTS hive_votes (
CREATE
INDEX
IF
NOT
EXISTS
hive_votes_voter_id_idx
ON
hive_votes
(
voter_id
);
CREATE
INDEX
IF
NOT
EXISTS
hive_votes_author_id_idx
ON
hive_votes
(
author_id
);
CREATE
INDEX
IF
NOT
EXISTS
hive_votes_permlink_id_idx
ON
hive_votes
(
permlink_id
);
CREATE
INDEX
IF
NOT
EXISTS
hive_votes_upvote_idx
ON
hive_votes
(
vote_percent
)
WHERE
vote_percent
>
0
;
CREATE
INDEX
IF
NOT
EXISTS
hive_votes_downvote_idx
ON
hive_votes
(
vote_percent
)
WHERE
vote_percent
<
0
;
-- Copy data from hive_posts table to new table
-- RAISE NOTICE 'Copy data from hive_posts table to new table';
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment