Skip to content

Commit

Permalink
mdb performance tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
artyl committed Jun 25, 2020
1 parent 2107368 commit b7c341f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
15 changes: 10 additions & 5 deletions plugin/dbengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@
'CalcTurnOff':'Откл (Р)',}

addition_phone_fields = {'MBPhoneNumber': '[nvarchar] (150)'}
addition_indexes = ['idx_QueryDateTime ON Phones (QueryDateTime ASC)']
addition_queries = ["delete from phones where phonenumber like 'p_%' or operator='p_test1' or (phonenumber='tinkoff' and operator='???')"]
addition_indexes = ['idx_QueryDateTime ON Phones (QueryDateTime ASC)',
'idx_Phonenumber ON Phones (PhoneNumber)',
'idx_MBPhonenumber ON Phones (MBPhoneNumber)']
addition_queries = [
"delete from phones where phonenumber like 'p_%' or operator='p_test1' or (phonenumber='tinkoff' and operator='???')"]

class dbengine():
def __init__(self, dbname, updatescheme=True, fast=False):
Expand Down Expand Up @@ -248,13 +251,15 @@ def update_sqlite_from_mdb_core(deep=None):
mdb = mdbengine(mdbfilename)
# Дата согласно указанному deep от которой сверяем данные
dd = datetime.datetime.now() - datetime.timedelta(days=deep)
db.cur.execute("update phones set QueryDateTime=datetime(QueryDateTime) where datetime(QueryDateTime)<>QueryDateTime");
logging.debug(f'Fix miliseconds {db.cur.fetchall()}')
db.conn.commit()
#logging.debug(f'Fix miliseconds {db.cur.fetchall()}')
#db.cur.execute("update phones set QueryDateTime=datetime(QueryDateTime) where datetime(QueryDateTime)<>QueryDateTime");
#db.conn.commit()
logging.debug(f'Read from sqlite QueryDateTime>{dd}')
db.cur.execute("SELECT * FROM phones where QueryDateTime>?", [dd]);
sqldata = db.cur.fetchall()
dsqlite = {datetime.datetime.strptime(i[3].split('.')[0],'%Y-%m-%d %H:%M:%S').timestamp():i for i in sqldata}
# теперь все то же самое из базы MDB
logging.debug(f'Read from mdb QueryDateTime>{dd}')
mdb.cur.execute("SELECT * FROM phones where QueryDateTime>?", [dd]);
mdbdata = mdb.cur.fetchall()
dmdb = {i[1].timestamp():i for i in mdbdata}
Expand Down
32 changes: 18 additions & 14 deletions plugin/mbplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@ def main():
logging.error(exception_text)
sys.stdout.write(exception_text)
return -1
# request указан в переменной RequestVariable ?
try:
RequestVariable = os.environ['RequestVariable'].strip(' "')
root = etree.fromstring(RequestVariable)
login = root.find('Login').text
password = root.find('Password').text
except Exception:
exception_text = f'Не смог взять RequestVariable: {"".join(traceback.format_exception(*sys.exc_info()))}'
logging.error(exception_text)
sys.stdout.write(exception_text)
return -1
logging.debug(f'request = {RequestVariable}')
if len(sys.argv) == 4: # plugin login password
login = sys.argv[2]
password = sys.argv[3]
else: # request указан в переменной RequestVariable ?
try:
RequestVariable = os.environ['RequestVariable'].strip(' "')
root = etree.fromstring(RequestVariable)
login = root.find('Login').text
password = root.find('Password').text
except Exception:
exception_text = f'Не смог взять RequestVariable: {"".join(traceback.format_exception(*sys.exc_info()))}'
logging.error(exception_text)
sys.stdout.write(exception_text)
return -1
logging.debug(f'request = {RequestVariable}')

# Запуск плагина
logging.info(f'Start {lang} {plugin} {login}')
try:
Expand Down Expand Up @@ -77,6 +81,6 @@ def main():


if __name__ == '__main__':
# todo for test usage mbplugin.py login password
# or mbplugin.py lang plugin login password
# todo mbplugin.py plugin (RequestVariable=<Request>\n<ParentWindow>007F09DA</ParentWindow>\n<Login>p_test_1234567</Login>\n<Password>pass1234</Password>\n</Request>)
# todo mbplugin.py plugin login password (нужен для отладки)
main()
2 changes: 1 addition & 1 deletion setup_and_check.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ start "" "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\run_webserver.

cd "%~dp0"
echo à®¢¥à塞 çâ® ¢á¥ à ¡®â ¥â JSMB LH PLUGIN
python\python -c "import re,requests;url=re.findall(r'(?usi)(http://127.0.0.1:.*?).\+',open('jsmblhplugin\\p_test1_localweb.jsmb').read())[0];print(requests.session().get(url+'123/456/789',timeout=1).content.decode('cp1251'))"
python\python -c "import re,requests;url=re.findall(r'(?usi)(http://127.0.0.1:.*?).\+',open('jsmblhplugin\\p_test1_localweb.jsmb').read())[0];print(requests.session().get(url+'123/456/789').content.decode('cp1251'))"

cd "%~dp0"
echo à®¢¥à塞 çâ® ¢á¥ à ¡®â ¥â DLL PLUGIN
Expand Down

0 comments on commit b7c341f

Please sign in to comment.