fix masto user sync and reduce frequency
This commit is contained in:
parent
c664f2ce4e
commit
0044e32864
2 changed files with 16 additions and 1 deletions
|
@ -9,12 +9,13 @@ from users.models import User
|
|||
|
||||
@JobManager.register
|
||||
class MastodonUserSync(BaseJob):
|
||||
batch = 8
|
||||
batch = 16
|
||||
interval_hours = 3
|
||||
interval = timedelta(hours=interval_hours)
|
||||
|
||||
def run(self):
|
||||
logger.info("Mastodon User Sync start.")
|
||||
inactive_threshold = timezone.now() - timedelta(days=60)
|
||||
qs = (
|
||||
User.objects.exclude(
|
||||
preference__mastodon_skip_userinfo=True,
|
||||
|
@ -32,5 +33,10 @@ class MastodonUserSync(BaseJob):
|
|||
.exclude(mastodon_token="")
|
||||
)
|
||||
for user in qs.iterator():
|
||||
if user.last_login < inactive_threshold:
|
||||
last_usage = user.last_usage
|
||||
if not last_usage or last_usage < inactive_threshold:
|
||||
logger.warning(f"Skip {user} because of inactivity.")
|
||||
continue
|
||||
user.refresh_mastodon_data()
|
||||
logger.info(f"Mastodon User Sync finished.")
|
||||
|
|
|
@ -214,6 +214,13 @@ class User(AbstractUser):
|
|||
def registration_complete(self):
|
||||
return self.username is not None
|
||||
|
||||
@property
|
||||
def last_usage(self):
|
||||
from journal.models import Piece
|
||||
|
||||
p = Piece.objects.filter(owner=self.identity).order_by("-edited_time").first()
|
||||
return p.edited_time if p else None
|
||||
|
||||
def clear(self):
|
||||
if self.mastodon_site == "removed" and not self.is_active:
|
||||
return
|
||||
|
@ -344,6 +351,8 @@ class User(AbstractUser):
|
|||
"mastodon_mutes",
|
||||
"mastodon_blocks",
|
||||
"mastodon_domain_blocks",
|
||||
"mastodon_last_refresh",
|
||||
"mastodon_last_reachable",
|
||||
]
|
||||
)
|
||||
if not self.preference.mastodon_skip_userinfo:
|
||||
|
|
Loading…
Add table
Reference in a new issue