eric6/WebBrowser/SafeBrowsing/SafeBrowsingCache.py

changeset 7628
f904d0eef264
parent 7360
9190402e4505
child 7759
51aa6c6b66f7
equal deleted inserted replaced
7626:7f643d41464e 7628:f904d0eef264
282 (value, threat_type, platform_type, threat_entry_type, 282 (value, threat_type, platform_type, threat_entry_type,
283 malware_threat_type, downloaded_at) 283 malware_threat_type, downloaded_at)
284 VALUES 284 VALUES
285 (?, ?, ?, ?, ?, current_timestamp) 285 (?, ?, ?, ?, ?, current_timestamp)
286 """ 286 """
287 updateQueryStr = """ 287 updateQueryStr = (
288 """
288 UPDATE full_hash SET 289 UPDATE full_hash SET
289 expires_at=datetime(current_timestamp, '+{0} SECONDS') 290 expires_at=datetime(current_timestamp, '+{0} SECONDS')
290 WHERE value=? AND threat_type=? AND platform_type=? AND 291 WHERE value=? AND threat_type=? AND platform_type=? AND
291 threat_entry_type=? 292 threat_entry_type=?
292 """.format(int(cacheDuration)) 293 """.format(int(cacheDuration))
294 )
293 295
294 db = QSqlDatabase.database(self.__connectionName) 296 db = QSqlDatabase.database(self.__connectionName)
295 if db.isOpen(): 297 if db.isOpen():
296 db.transaction() 298 db.transaction()
297 try: 299 try:
350 given time. 352 given time.
351 353
352 @param keepExpiredFor time period in seconds of entries to be expired 354 @param keepExpiredFor time period in seconds of entries to be expired
353 @type int or float 355 @type int or float
354 """ 356 """
355 queryStr = """ 357 queryStr = (
358 """
356 DELETE FROM full_hash 359 DELETE FROM full_hash
357 WHERE expires_at=datetime(current_timestamp, '{0} SECONDS') 360 WHERE expires_at=datetime(current_timestamp, '{0} SECONDS')
358 """.format(int(keepExpiredFor)) 361 """.format(int(keepExpiredFor))
362 )
359 363
360 db = QSqlDatabase.database(self.__connectionName) 364 db = QSqlDatabase.database(self.__connectionName)
361 if db.isOpen(): 365 if db.isOpen():
362 db.transaction() 366 db.transaction()
363 try: 367 try:
379 @type bytes 383 @type bytes
380 @param negativeCacheDuration time in seconds the entry should remain 384 @param negativeCacheDuration time in seconds the entry should remain
381 in the cache 385 in the cache
382 @type int or float 386 @type int or float
383 """ 387 """
384 queryStr = """ 388 queryStr = (
389 """
385 UPDATE hash_prefix 390 UPDATE hash_prefix
386 SET negative_expires_at=datetime(current_timestamp, '+{0} SECONDS') 391 SET negative_expires_at=datetime(current_timestamp, '+{0} SECONDS')
387 WHERE value=? AND threat_type=? AND platform_type=? AND 392 WHERE value=? AND threat_type=? AND platform_type=? AND
388 threat_entry_type=? 393 threat_entry_type=?
389 """.format(int(negativeCacheDuration)) 394 """.format(int(negativeCacheDuration))
395 )
390 396
391 db = QSqlDatabase.database(self.__connectionName) 397 db = QSqlDatabase.database(self.__connectionName)
392 if db.isOpen(): 398 if db.isOpen():
393 db.transaction() 399 db.transaction()
394 try: 400 try:
655 @param threatList threat list to delete hash prefixes of 661 @param threatList threat list to delete hash prefixes of
656 @type ThreatList 662 @type ThreatList
657 @param indexes list of indexes of prefixes to be removed 663 @param indexes list of indexes of prefixes to be removed
658 @type list of int 664 @type list of int
659 """ 665 """
660 queryStr = """ 666 queryStr = (
667 """
661 DELETE FROM hash_prefix 668 DELETE FROM hash_prefix
662 WHERE threat_type=? AND platform_type=? AND 669 WHERE threat_type=? AND platform_type=? AND
663 threat_entry_type=? AND value IN ({0}) 670 threat_entry_type=? AND value IN ({0})
664 """ 671 """
672 )
665 batchSize = 40 673 batchSize = 40
666 674
667 prefixesToRemove = self.getHashPrefixValuesToRemove( 675 prefixesToRemove = self.getHashPrefixValuesToRemove(
668 threatList, indexes) 676 threatList, indexes)
669 if prefixesToRemove: 677 if prefixesToRemove:
690 del query 698 del query
691 QCoreApplication.processEvents( 699 QCoreApplication.processEvents(
692 QEventLoop.AllEvents, self.maxProcessEventsTime) 700 QEventLoop.AllEvents, self.maxProcessEventsTime)
693 finally: 701 finally:
694 db.commit() 702 db.commit()
703
704 #
705 # eflag: noqa = S608

eric ide

mercurial