forked from rDrama/rDrama
Persist activity timestamp to users.
parent
35720c0a63
commit
f6b6997f61
|
@ -70,6 +70,7 @@ class User(Base):
|
||||||
received_award_count = Column(Integer, default=0)
|
received_award_count = Column(Integer, default=0)
|
||||||
created_utc = Column(Integer)
|
created_utc = Column(Integer)
|
||||||
admin_level = Column(Integer, default=0)
|
admin_level = Column(Integer, default=0)
|
||||||
|
last_active = Column(Integer, default=0, nullable=False)
|
||||||
coins_spent = Column(Integer, default=0)
|
coins_spent = Column(Integer, default=0)
|
||||||
lootboxes_bought = Column(Integer, default=0)
|
lootboxes_bought = Column(Integer, default=0)
|
||||||
agendaposter = Column(Integer, default=0)
|
agendaposter = Column(Integer, default=0)
|
||||||
|
@ -198,6 +199,12 @@ class User(Base):
|
||||||
|
|
||||||
return time.strftime("%d %b %Y", time.gmtime(self.created_utc))
|
return time.strftime("%d %b %Y", time.gmtime(self.created_utc))
|
||||||
|
|
||||||
|
@property
|
||||||
|
@lazy
|
||||||
|
def last_active_date(self):
|
||||||
|
if self.last_active == 0:
|
||||||
|
return "never"
|
||||||
|
return str(time.strftime("%d %b %Y", time.gmtime(self.last_active)))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
|
@ -673,6 +680,13 @@ class User(Base):
|
||||||
def created_datetime(self):
|
def created_datetime(self):
|
||||||
return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc)))
|
return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc)))
|
||||||
|
|
||||||
|
@property
|
||||||
|
@lazy
|
||||||
|
def last_active_datetime(self):
|
||||||
|
if self.last_active == 0:
|
||||||
|
return "never"
|
||||||
|
return str(time.strftime("%Y-%m-%d %H:%M:%SZ", time.gmtime(self.last_active)))
|
||||||
|
|
||||||
@lazy
|
@lazy
|
||||||
def subscribed_idlist(self, page=1):
|
def subscribed_idlist(self, page=1):
|
||||||
posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id).all()
|
posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id).all()
|
||||||
|
|
|
@ -143,6 +143,7 @@ HOLE_COST = 0
|
||||||
HOLE_INACTIVITY_DELETION = False
|
HOLE_INACTIVITY_DELETION = False
|
||||||
PIN_LIMIT = 3
|
PIN_LIMIT = 3
|
||||||
POST_RATE_LIMIT = '1/second;2/minute;10/hour;50/day'
|
POST_RATE_LIMIT = '1/second;2/minute;10/hour;50/day'
|
||||||
|
LOGGEDIN_ACTIVE_TIME = 15 * 60
|
||||||
|
|
||||||
NOTIFICATIONS_ID = 1
|
NOTIFICATIONS_ID = 1
|
||||||
AUTOJANNY_ID = 2
|
AUTOJANNY_ID = 2
|
||||||
|
|
|
@ -53,15 +53,21 @@ def get_logged_in_user():
|
||||||
if v:
|
if v:
|
||||||
if session["session_id"] in loggedout: del loggedout[session["session_id"]]
|
if session["session_id"] in loggedout: del loggedout[session["session_id"]]
|
||||||
loggedin[v.id] = timestamp
|
loggedin[v.id] = timestamp
|
||||||
|
# Check against last_active + ACTIVE_TIME to reduce frequency of
|
||||||
|
# UPDATEs in exchange for a ±ACTIVE_TIME margin of error.
|
||||||
|
if (v.last_active + LOGGEDIN_ACTIVE_TIME) < timestamp:
|
||||||
|
v.last_active = timestamp
|
||||||
|
g.db.add(v)
|
||||||
|
g.db.commit()
|
||||||
else:
|
else:
|
||||||
ua = str(user_agents.parse(g.agent))
|
ua = str(user_agents.parse(g.agent))
|
||||||
if not ua.startswith('Spider') and 'bot' not in ua.lower():
|
if not ua.startswith('Spider') and 'bot' not in ua.lower():
|
||||||
loggedout[session["session_id"]] = (timestamp, ua)
|
loggedout[session["session_id"]] = (timestamp, ua)
|
||||||
|
|
||||||
g.loggedin_counter = len([x for x in loggedin.values() if timestamp-x<15*60])
|
g.loggedin_counter = len([x for x in loggedin.values() if timestamp-x < LOGGEDIN_ACTIVE_TIME])
|
||||||
cache.set(f'{SITE}_loggedin', loggedin)
|
cache.set(f'{SITE}_loggedin', loggedin)
|
||||||
|
|
||||||
g.loggedout_counter = len([x for x in loggedout.values() if timestamp-x[0]<15*60])
|
g.loggedout_counter = len([x for x in loggedout.values() if timestamp-x[0] < LOGGEDIN_ACTIVE_TIME])
|
||||||
cache.set(f'{SITE}_loggedout', loggedout)
|
cache.set(f'{SITE}_loggedout', loggedout)
|
||||||
|
|
||||||
g.v = v
|
g.v = v
|
||||||
|
|
|
@ -63,14 +63,14 @@ def kippy(v):
|
||||||
@app.get('/admin/loggedin')
|
@app.get('/admin/loggedin')
|
||||||
@admin_level_required(2)
|
@admin_level_required(2)
|
||||||
def loggedin_list(v):
|
def loggedin_list(v):
|
||||||
ids = [x for x,val in cache.get(f'{SITE}_loggedin').items() if time.time()-val<15*60]
|
ids = [x for x,val in cache.get(f'{SITE}_loggedin').items() if time.time()-val < LOGGEDIN_ACTIVE_TIME]
|
||||||
users = g.db.query(User).filter(User.id.in_(ids)).order_by(User.admin_level.desc(), User.truecoins.desc()).all()
|
users = g.db.query(User).filter(User.id.in_(ids)).order_by(User.admin_level.desc(), User.truecoins.desc()).all()
|
||||||
return render_template("loggedin.html", v=v, users=users)
|
return render_template("loggedin.html", v=v, users=users)
|
||||||
|
|
||||||
@app.get('/admin/loggedout')
|
@app.get('/admin/loggedout')
|
||||||
@admin_level_required(2)
|
@admin_level_required(2)
|
||||||
def loggedout_list(v):
|
def loggedout_list(v):
|
||||||
users = sorted([val[1] for x,val in cache.get(f'{SITE}_loggedout').items() if time.time()-val[0]<15*60])
|
users = sorted([val[1] for x,val in cache.get(f'{SITE}_loggedout').items() if time.time()-val[0] < LOGGEDIN_ACTIVE_TIME])
|
||||||
return render_template("loggedout.html", v=v, users=users)
|
return render_template("loggedout.html", v=v, users=users)
|
||||||
|
|
||||||
@app.get('/admin/merge/<id1>/<id2>')
|
@app.get('/admin/merge/<id1>/<id2>')
|
||||||
|
|
|
@ -125,6 +125,10 @@
|
||||||
<a href="/@{{u.username}}/following" id="profile--following">follows {{u.follow_count}} user{{'s' if u.follow_count != 1 else ''}}</a>
|
<a href="/@{{u.username}}/following" id="profile--following">follows {{u.follow_count}} user{{'s' if u.follow_count != 1 else ''}}</a>
|
||||||
|
|
||||||
<span id="profile--joined">joined <span data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.created_datetime}}">{{u.created_date}}</span></span>
|
<span id="profile--joined">joined <span data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.created_datetime}}">{{u.created_date}}</span></span>
|
||||||
|
|
||||||
|
{% if v and v.admin_level >= 2 -%}
|
||||||
|
<span id="profile--lastactive" class="ml-2">last active <span data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.last_active_datetime}}">{{u.last_active_date}}</span></span>
|
||||||
|
{%- endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if u.basedcount %}<p class="text-muted" id="profile--based">Based Count: {{u.basedcount}}</p>{% endif %}
|
{% if u.basedcount %}<p class="text-muted" id="profile--based">Based Count: {{u.basedcount}}</p>{% endif %}
|
||||||
|
|
||||||
|
@ -427,6 +431,10 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<br><span id="profile--joined">joined <span data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.created_datetime}}" class="font-weight-bold">{{u.created_date}}</span></span>
|
<br><span id="profile--joined">joined <span data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.created_datetime}}" class="font-weight-bold">{{u.created_date}}</span></span>
|
||||||
|
|
||||||
|
{% if v and v.admin_level >= 2 -%}
|
||||||
|
<br><span id="profile--lastactive">last active <span data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.last_active_datetime}}" class="font-weight-bold">{{u.last_active_date}}</span></span>
|
||||||
|
{%- endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if u.bio_html %}
|
{% if u.bio_html %}
|
||||||
<div class="text-muted text-break" id="profile--bio">{{u.bio_html | safe}}</div>
|
<div class="text-muted text-break" id="profile--bio">{{u.bio_html | safe}}</div>
|
||||||
|
|
|
@ -679,7 +679,8 @@ CREATE TABLE public.users (
|
||||||
total_held_lottery_tickets integer DEFAULT 0 NOT NULL,
|
total_held_lottery_tickets integer DEFAULT 0 NOT NULL,
|
||||||
total_lottery_winnings integer DEFAULT 0 NOT NULL,
|
total_lottery_winnings integer DEFAULT 0 NOT NULL,
|
||||||
can_gamble boolean DEFAULT true NOT NULL,
|
can_gamble boolean DEFAULT true NOT NULL,
|
||||||
offsitementions boolean DEFAULT false NOT NULL
|
offsitementions boolean DEFAULT false NOT NULL,
|
||||||
|
last_active integer DEFAULT 0 NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue