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
dc21d325
Commit
dc21d325
authored
4 years ago
by
Mariusz Trela
Browse files
Options
Downloads
Patches
Plain Diff
Final version of `hive_accounts_info_view` view
parent
92b1f823
No related branches found
No related tags found
5 merge requests
!456
Release candidate v1 24
,
!230
Setup monitoring with pghero
,
!138
Small typos fixed
,
!135
Enable postgres monitoring on CI server
,
!110
Teh call `get_profile` works
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hive/db/schema.py
+68
-0
68 additions, 0 deletions
hive/db/schema.py
hive/server/bridge_api/objects.py
+1
-1
1 addition, 1 deletion
hive/server/bridge_api/objects.py
hive/server/condenser_api/cursor.py
+5
-6
5 additions, 6 deletions
hive/server/condenser_api/cursor.py
with
74 additions
and
7 deletions
hive/db/schema.py
+
68
−
0
View file @
dc21d325
...
...
@@ -560,6 +560,74 @@ def setup(db):
"""
db
.
query_no_return
(
sql
)
# In original hivemind, a value of 'active_at' was calculated from
# max
# {
# created ( account_create_operation ),
# last_account_update ( account_update_operation/account_update2_operation ),
# last_post ( comment_operation - only creation )
# last_root_post ( comment_operation - only creation + only ROOT ),
# last_vote_time ( vote_operation )
# }
# In order to simplify calculations, `last_account_update` is not taken into consideration, because this updating accounts is very rare
# and posting/voting after an account updating, fixes `active_at` value immediately.
sql
=
"""
DROP VIEW IF EXISTS public.hive_accounts_info_view;
CREATE OR REPLACE VIEW public.hive_accounts_info_view
AS
SELECT
id,
name,
COALESCE(
(
select count(*) post_count
FROM hive_posts hp
WHERE ha.id=hp.author_id
GROUP BY hp.author_id
),
0
) post_count,
COALESCE(
(
select max(hp.created_at)
FROM hive_posts hp
WHERE ha.id=hp.author_id
GROUP BY hp.author_id
),
'
1970-01-01 00:00:00.0
'
) post_active_at,
COALESCE(
(
select max(hv.last_update)
from hive_votes hv
WHERE ha.id=hv.voter_id
GROUP BY hv.voter_id
),
'
1970-01-01 00:00:00.0
'
) AS vote_active_at,
created_at,
display_name,
about,
reputation,
profile_image,
location,
website,
cover_image,
rank,
following,
followers,
proxy,
proxy_weight,
lastread_at,
cached_at,
raw_json
FROM
hive_accounts ha
"""
db
.
query_no_return
(
sql
)
sql
=
"""
DROP VIEW IF EXISTS public.hive_posts_view;
...
...
This diff is collapsed.
Click to expand it.
hive/server/bridge_api/objects.py
+
1
−
1
View file @
dc21d325
...
...
@@ -201,7 +201,7 @@ def _condenser_profile_object(row):
'
id
'
:
row
[
'
id
'
],
'
name
'
:
row
[
'
name
'
],
'
created
'
:
json_date
(
row
[
'
created_at
'
]),
'
active
'
:
json_date
(
row
[
'
active_at
'
]
),
'
active
'
:
json_date
(
max
(
row
[
'
created_at
'
],
row
[
'
post_active_at
'
],
row
[
'
vote_active_at
'
]
)
),
'
post_count
'
:
row
[
'
post_count
'
],
'
reputation
'
:
row
[
'
reputation
'
],
'
blacklists
'
:
blacklists
,
...
...
This diff is collapsed.
Click to expand it.
hive/server/condenser_api/cursor.py
+
5
−
6
View file @
dc21d325
...
...
@@ -439,11 +439,8 @@ async def get_accounts(db, accounts: list):
ret
=
[]
names
=
[
"'
{}
'"
.
format
(
a
)
for
a
in
accounts
]
sql
=
"""
SELECT created_at, reputation, display_name, about,
location, website, profile_image, cover_image, followers, following,
proxy, post_count, proxy_weight, vote_weight, rank,
lastread_at, active_at, cached_at, raw_json
FROM hive_accounts WHERE name IN ({})
"""
.
format
(
"
,
"
.
join
(
names
))
sql
=
"""
SELECT *
FROM hive_accounts_info_view WHERE name IN ({})
"""
.
format
(
"
,
"
.
join
(
names
))
result
=
await
db
.
query_all
(
sql
)
for
row
in
result
:
...
...
@@ -466,7 +463,9 @@ async def get_accounts(db, accounts: list):
account_data
[
'
vote_weight
'
]
=
row
.
vote_weight
account_data
[
'
rank
'
]
=
row
.
rank
account_data
[
'
lastread_at
'
]
=
row
.
lastread_at
.
isoformat
()
account_data
[
'
active_at
'
]
=
row
.
active_at
.
isoformat
()
account_data
[
'
active_at
'
]
=
max
(
row
.
created_at
,
row
.
post_active_at
,
row
.
vote_active_at
).
isoformat
()
account_data
[
'
cached_at
'
]
=
row
.
cached_at
.
isoformat
()
ret
.
append
(
account_data
)
...
...
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