Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commitf45e944

Browse files
authored
feat(status): realtime visitors (#442)
* refactor(statistics): online-status & update Telsa stack* chore(status): online visitors set to 1* fix(ci): rss tesla client name* fix(ci): community query arg* fix(ci): community query arg* fix(ci): test errors
1 parent7a79b13 commitf45e944

File tree

29 files changed

+211
-82
lines changed

29 files changed

+211
-82
lines changed

‎config/config.exs‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,22 @@ config :groupher_server, :cache,
139139
common:%{
140140
name::common,
141141
size:5000,
142-
minutes:10
142+
seconds:10*60
143143
},
144144
user_login:%{
145145
name::user_login,
146146
size:10_000,
147-
minutes:10_080
147+
seconds:10_080*60
148148
},
149149
blog_rss:%{
150150
name::blog_rss,
151151
size:1000,
152-
minutes:15
152+
seconds:15*60
153+
},
154+
online_status:%{
155+
name::online_status,
156+
size:30,
157+
seconds:25
153158
}
154159
}
155160

@@ -162,9 +167,16 @@ config :groupher_server, Helper.Scheduler,
162167
# Every 59 minutes
163168
{"*/59 * * * *",{Helper.Scheduler,:articles_audition,[]}},
164169
# Every 29 minutes
165-
{"*/29 * * * *",{Helper.Scheduler,:comments_audition,[]}}
170+
{"*/29 * * * *",{Helper.Scheduler,:comments_audition,[]}},
171+
online_status:[
172+
# Runs every 20 seconds
173+
schedule:{:extended,"*/20"},
174+
task:{Helper.Scheduler,:gather_online_status,[]}
175+
]
166176
]
167177

178+
config:tesla,adapter:Tesla.Adapter.Hackney
179+
168180
# handle background jobs
169181
config:rihanna,
170182
jobs_table_name:"background_jobs",

‎config/prod.exs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ config :groupher_server, :github_oauth,
8989
client_secret:System.get_env("OAUTH_GITHUB_CLIENT_SECRET"),
9090
redirect_uri:System.get_env("OAUTH_GITHUB_REDIRECT_URI")
9191

92-
config:groupher_server,:radar_search,ip_service:System.get_env("IP_LOCATE_KEY")
92+
config:groupher_server,:ip_locate,ip_service:System.get_env("IP_LOCATE_KEY")
93+
config:groupher_server,:plausible,token:System.get_env("PLAUSIBLE_TOKEN")
9394

9495
config:sentry,
9596
dsn:System.get_env("SENTRY_DSN"),

‎lib/groupher_server/accounts/delegates/profile.ex‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defmodule GroupherServer.Accounts.Delegate.Profile do
1313

1414
aliasGroupherServer.Accounts.Delegate.Fans
1515

16-
aliasHelper.{Guardian,ORM,QueryBuilder,RadarSearch}
16+
aliasHelper.{Guardian,ORM,QueryBuilder,IP2City}
1717
aliasEcto.Multi
1818

1919
@default_user_metaEmbeds.UserMeta.default_meta()
@@ -92,7 +92,7 @@ defmodule GroupherServer.Accounts.Delegate.Profile do
9292
update geo info for user, include geo_city & remote ip
9393
"""
9494
defupdate_geo(%User{geo_city:geo_city}=user,remote_ip)whenis_nil(geo_city)do
95-
caseRadarSearch.locate_city(remote_ip)do
95+
caseIP2City.locate_city(remote_ip)do
9696
{:ok,city}->
9797
update_profile(user,%{geo_city:city,remote_ip:remote_ip})
9898

‎lib/groupher_server/application.ex‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ defmodule GroupherServer.Application do
4747
# worker(Cachex, [:common, Cache.config(:common)], id: :common),
4848
# worker(Cachex, [:user_login, Cache.config(:user_login)], id: :user_login),
4949
# worker(Cachex, [:blog_rss, Cache.config(:blog_rss)], id: :blog_rss),
50+
5051
@cache_pool
5152
|>Map.keys()
5253
|>Enum.reduce([],fnkey,acc->

‎lib/groupher_server/cms/delegates/blog_curd.ex‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ defmodule GroupherServer.CMS.Delegate.BlogCURD do
9898
end
9999

100100
defpget_rssinfo_and_cache(rss)do
101-
# {:ok, feed} = RSS.get(rss)
102-
with{:ok,rssinfo}<-RSS.get(rss)do
101+
with{:ok,rssinfo}<-RSS.query(rss)do
103102
Cache.put(@cache_pool,rss,rssinfo)
104103
{:ok,rssinfo}
105104
else

‎lib/groupher_server/cms/delegates/community_operation.ex‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule GroupherServer.CMS.Delegate.CommunityOperation do
44
"""
55
importShortMaps
66

7-
aliasHelper.{Certification,RadarSearch,ORM}
7+
aliasHelper.{Certification,IP2City,ORM}
88

99
aliasGroupherServer.{Accounts,CMS,Repo}
1010

@@ -285,7 +285,7 @@ defmodule GroupherServer.CMS.Delegate.CommunityOperation do
285285
end
286286

287287
defpget_user_geocity(nil,remote_ip)do
288-
caseRadarSearch.locate_city(remote_ip)do
288+
caseIP2City.locate_city(remote_ip)do
289289
{:ok,city}->{:ok,city}
290290
{:error,_}->{:error,"update_community geo error"}
291291
end

‎lib/groupher_server/statistics/delegates/status.ex‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,54 @@ defmodule GroupherServer.Statistics.Delegate.Status do
77
importShortMaps
88

99
aliasGroupherServer.CMS
10-
aliasCMS.Model.{Post,Job,Repo,Community,Thread,Category,ArticleTag}
11-
aliasHelper.ORM
1210

11+
aliasCMS.Model.{
12+
Post,
13+
Job,
14+
Guide,
15+
Meetup,
16+
Drink,
17+
Blog,
18+
Radar,
19+
Works,
20+
Drink,
21+
Community,
22+
Thread,
23+
Category,
24+
ArticleTag
25+
}
26+
27+
aliasHelper.{ORM,Cache}
28+
29+
@cache_pool:online_status
1330
@count_filter%{page:1,size:1}
1431

32+
defonline_status()do
33+
with{:ok,realtime_visitors}<-Cache.get(@cache_pool,:realtime_visitors)do
34+
{:ok,%{realtime_visitors:realtime_visitors}}
35+
else
36+
_->
37+
{:ok,%{realtime_visitors:1}}
38+
end
39+
end
40+
1541
defcount_statusdo
1642
{:ok,%{total_count:communities_count}}=find_total_count(Community)
1743
{:ok,%{total_count:posts_count}}=find_total_count(Post)
1844
{:ok,%{total_count:jobs_count}}=find_total_count(Job)
19-
{:ok,%{total_count:repos_count}}=find_total_count(Repo)
45+
{:ok,%{total_count:blogs_count}}=find_total_count(Blog)
46+
{:ok,%{total_count:works_count}}=find_total_count(Works)
47+
{:ok,%{total_count:meetups_count}}=find_total_count(Meetup)
48+
{:ok,%{total_count:guides_count}}=find_total_count(Guide)
49+
{:ok,%{total_count:radars_count}}=find_total_count(Radar)
50+
{:ok,%{total_count:drinks_count}}=find_total_count(Drink)
2051

2152
{:ok,%{total_count:threads_count}}=find_total_count(Thread)
2253
{:ok,%{total_count:article_tags_count}}=find_total_count(ArticleTag)
2354
{:ok,%{total_count:categories_count}}=find_total_count(Category)
2455

2556
{:ok,
26-
~m(communities_count posts_count jobs_countrepos_count threads_count article_tags_count categories_count)a}
57+
~m(communities_count posts_count jobs_countworks_count meetups_count guides_count radars_count blogs_count drinks_count threads_count article_tags_count categories_count)a}
2758
end
2859

2960
defpfind_total_count(queryable),do:ORM.find_all(queryable,@count_filter)

‎lib/groupher_server/statistics/statistics.ex‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ defmodule GroupherServer.Statistics do
2121

2222
# countStatus
2323
defdelegatecount_status(),to:Status
24+
defdelegateonline_status(),to:Status
2425
end

‎lib/groupher_server_web/resolvers/statistics_resolver.ex‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ defmodule GroupherServerWeb.Resolvers.Statistics do
2020
Statistics.list_cities_info()
2121
end
2222

23+
defonline_status(_root,_args,_info)do
24+
Statistics.online_status()
25+
end
26+
2327
defcount_status(_root,_args,_info)do
2428
Statistics.count_status()
2529
end

‎lib/groupher_server_web/schema/statistics/statistics_queries.ex‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ defmodule GroupherServerWeb.Schema.Statistics.Queries do
1010
resolve(&R.Statistics.list_cities_geo_info/3)
1111
end
1212

13+
@desc"basic online status"
14+
field:online_status,:online_status_infodo
15+
arg(:freshkey,:string)
16+
17+
resolve(&R.Statistics.online_status/3)
18+
end
19+
1320
@desc"basic site info in total counts format"
1421
field:count_status,:count_status_infodo
1522
middleware(M.Passport,claim:"cms->root")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp