NOT WORKING Cache SQL querys to reduce amount of querys
This commit is contained in:
28
mysqlred.py
28
mysqlred.py
@@ -80,6 +80,13 @@ class MysqlRedPage( MysqlRed ):
|
|||||||
MySQL-db Interface for handling querys for RedPages
|
MySQL-db Interface for handling querys for RedPages
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Class variables for storing cached querys
|
||||||
|
__cached_update = []
|
||||||
|
__cached_insert_data = []
|
||||||
|
__insert_query = 'INSERT INTO `red_pages` \
|
||||||
|
( page_id, page_title, rev_id, status ) \
|
||||||
|
VALUES ( ?, ?, ?, ? );'
|
||||||
|
|
||||||
def __init__( self, page_id ):
|
def __init__( self, page_id ):
|
||||||
"""
|
"""
|
||||||
Creates a new instance, runs __init__ of parent class
|
Creates a new instance, runs __init__ of parent class
|
||||||
@@ -124,23 +131,12 @@ class MysqlRedPage( MysqlRed ):
|
|||||||
@param int status Page parsing status
|
@param int status Page parsing status
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cursor = type( self ).connection.cursor()
|
__cached_insert_data.apend( ( self.__page_id, page_title,
|
||||||
|
rev_id, status ) )
|
||||||
|
|
||||||
if not page_title:
|
# Manualy construct self.data dict
|
||||||
page_title = self.data[ 'page_title' ]
|
self.data = { 'page_id' : self.__page_id, 'rev_id' : rev_id,
|
||||||
if not rev_id:
|
'page_title' : page_title, 'status' : status }
|
||||||
rev_id = self.data[ 'rev_id' ]
|
|
||||||
|
|
||||||
query = 'INSERT INTO `red_pages` \
|
|
||||||
( page_id, page_title, rev_id, status ) \
|
|
||||||
VALUES ( ?, ?, ?, ? );'
|
|
||||||
data = ( self.__page_id, page_title, rev_id, status )
|
|
||||||
|
|
||||||
cursor.execute( query, data)
|
|
||||||
|
|
||||||
type( self ).connection.commit()
|
|
||||||
|
|
||||||
self.data = self.get_page()
|
|
||||||
|
|
||||||
def update_page( self, rev_id=None, page_title=None, status=0 ):
|
def update_page( self, rev_id=None, page_title=None, status=0 ):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user