return False
def can_update_profile(self, public_id, private_id, when=None):
- res = self.db.get("SELECT 1 FROM fireinfo_profiles \
- WHERE public_id = %s AND private_id = %s \
- AND time_updated + INTERVAL '60 minutes' <= then_or_now(%s) \
- AND time_valid >= then_or_now(%s) ORDER BY time_updated DESC LIMIT 1",
+ # Check if the profile has been updated very recently. If so we deny
+ # any new updates for some time.
+ res = self.db.get("WITH profiles AS (SELECT * FROM fireinfo_profiles \
+ WHERE public_id = %s AND private_id = %s AND time_valid >= then_or_now(%s) \
+ ORDER BY time_updated DESC LIMIT 1) \
+ SELECT 1 FROM profiles WHERE then_or_now(%s) <= \
+ time_updated + INTERVAL '60 minutes'",
public_id, private_id, when, when)
if res:
- return True
+ return False
- return False
+ # Check if a profile exists with a different private id that is still valid
+ res = self.db.get("SELECT 1 FROM fireinfo_profiles \
+ WHERE public_id = %s AND NOT private_id = %s \
+ AND time_valid >= then_or_now(%s) LIMIT 1", public_id, private_id, when)
+
+ if res:
+ return False
+
+ return True
def get_profile(self, public_id, private_id=None, when=None):
res = self.db.get("SELECT * FROM fireinfo_profiles \