Compare commits
No commits in common. "111ea307a99c220bae0e03fc901dbf0ac441f9ea" and "b7d140e36ab70d58f4aed60426eeb68e91b5dfa3" have entirely different histories.
111ea307a9
...
b7d140e36a
6 changed files with 24 additions and 57 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import codecs
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
@ -52,7 +53,7 @@ class Peer(object):
|
||||||
def apply_log(self):
|
def apply_log(self):
|
||||||
changes = []
|
changes = []
|
||||||
if os.path.exists(self._logpath):
|
if os.path.exists(self._logpath):
|
||||||
with open(self._logpath, 'r', encoding='utf-8', newline='\n') as fd:
|
with codecs.open(self._logpath, 'r', encoding='utf-8') as fd:
|
||||||
for line in fd:
|
for line in fd:
|
||||||
if line:
|
if line:
|
||||||
try:
|
try:
|
||||||
|
|
@ -446,9 +447,6 @@ def cleanup_peers():
|
||||||
other_peers[id] = peer.info['peers'][id]
|
other_peers[id] = peer.info['peers'][id]
|
||||||
known_peers.add(id)
|
known_peers.add(id)
|
||||||
for u in user.models.User.query.filter(user.models.User.id.notin_(list(known_peers))):
|
for u in user.models.User.query.filter(user.models.User.id.notin_(list(known_peers))):
|
||||||
if state.nodes and u.id in state.nodes.local:
|
if not 'local' in u.info and not u.pending:
|
||||||
continue
|
|
||||||
if not u.pending:
|
|
||||||
state.db.session.delete(u)
|
state.db.session.delete(u)
|
||||||
|
|
||||||
state.db.session.commit()
|
state.db.session.commit()
|
||||||
|
|
|
||||||
|
|
@ -95,4 +95,4 @@ FULLTEXT_SUPPORT = fulltext.platform_supported()
|
||||||
if not FULLTEXT_SUPPORT:
|
if not FULLTEXT_SUPPORT:
|
||||||
config['itemKeys'] = [k for k in config['itemKeys'] if k['id'] != 'fulltext']
|
config['itemKeys'] = [k for k in config['itemKeys'] if k['id'] != 'fulltext']
|
||||||
|
|
||||||
DB_VERSION = 20
|
DB_VERSION = 18
|
||||||
|
|
|
||||||
|
|
@ -379,10 +379,6 @@ class Update(Thread):
|
||||||
db_version = migrate_17()
|
db_version = migrate_17()
|
||||||
if db_version < 18:
|
if db_version < 18:
|
||||||
db_version = migrate_18()
|
db_version = migrate_18()
|
||||||
if db_version < 19:
|
|
||||||
db_version = migrate_19()
|
|
||||||
if db_version < 20:
|
|
||||||
db_version = migrate_20()
|
|
||||||
settings.server['db_version'] = db_version
|
settings.server['db_version'] = db_version
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
@ -621,10 +617,10 @@ def migrate_13():
|
||||||
with db.session() as session:
|
with db.session() as session:
|
||||||
revision = -1
|
revision = -1
|
||||||
qs = changelog.Changelog.query.filter_by(user_id=settings.USER_ID)
|
qs = changelog.Changelog.query.filter_by(user_id=settings.USER_ID)
|
||||||
with open(path, 'wb') as fd:
|
with open(path, 'w') as fd:
|
||||||
for c in qs.order_by('timestamp'):
|
for c in qs.order_by('timestamp'):
|
||||||
data = json.dumps([c.revision, c.timestamp, json.loads(c.data)], ensure_ascii=False).encode('utf-8')
|
data = json.dumps([c.revision, c.timestamp, json.loads(c.data)], ensure_ascii=False)
|
||||||
fd.write(data + b'\n')
|
fd.write(data + '\n')
|
||||||
revision = c.revision
|
revision = c.revision
|
||||||
if revision > -1:
|
if revision > -1:
|
||||||
settings.server['revision'] = revision
|
settings.server['revision'] = revision
|
||||||
|
|
@ -702,37 +698,3 @@ def migrate_18():
|
||||||
'CREATE INDEX ix_annotation_findnotes ON annotation (findnotes)'
|
'CREATE INDEX ix_annotation_findnotes ON annotation (findnotes)'
|
||||||
])
|
])
|
||||||
return 18
|
return 18
|
||||||
|
|
||||||
def migrate_19():
|
|
||||||
from user.models import User
|
|
||||||
with db.session():
|
|
||||||
peers = [u for u in User.query.filter_by(peered=True)]
|
|
||||||
peers.sort(key=lambda u: utils.user_sort_key(u.json()))
|
|
||||||
for u in peers:
|
|
||||||
peer = utils.get_peer(u.id)
|
|
||||||
if not peer.info.get('revision') and os.path.exists(peer._logpath) and os.path.getsize(peer._logpath):
|
|
||||||
logger.debug('try to apply pending logs for %s', u.id)
|
|
||||||
try:
|
|
||||||
peer.apply_log()
|
|
||||||
except:
|
|
||||||
logger.error('failed to apply log for %s', u.id)
|
|
||||||
return 19
|
|
||||||
|
|
||||||
def migrate_20():
|
|
||||||
from glob import glob
|
|
||||||
changed = False
|
|
||||||
for log in glob(os.path.join(settings.data_path, 'peers', '*.log')):
|
|
||||||
with open(log, 'rb') as fd:
|
|
||||||
data = fd.read()
|
|
||||||
try:
|
|
||||||
data.decode('utf-8')
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
data = data.decode('Windows-1252')
|
|
||||||
logger.error('convert %s to utf-8', log)
|
|
||||||
with open(log, 'wb') as fd:
|
|
||||||
fd.write(data.encode('utf-8'))
|
|
||||||
changed = True
|
|
||||||
|
|
||||||
if changed:
|
|
||||||
migrate_19()
|
|
||||||
return 20
|
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,17 @@ oml.ui.annotationPanel = function(options, self) {
|
||||||
// borderColor: 'transparent',
|
// borderColor: 'transparent',
|
||||||
float: 'right'
|
float: 'right'
|
||||||
}).bindEvent({
|
}).bindEvent({
|
||||||
|
change: function(data) {
|
||||||
|
if (data.id == 'showAnnotationUsers') {
|
||||||
|
var value = data.checked[0].id;
|
||||||
|
oml.UI.set('showAnnotationUsers', value);
|
||||||
|
oml.$ui.viewer.renderAnnotations();
|
||||||
|
} else if (data.id == 'sortAnnotations') {
|
||||||
|
var value = data.checked[0].id;
|
||||||
|
oml.UI.set('sortAnnotations', value);
|
||||||
|
oml.$ui.viewer.renderAnnotations();
|
||||||
|
}
|
||||||
|
},
|
||||||
click: function(data) {
|
click: function(data) {
|
||||||
var id = data.id;
|
var id = data.id;
|
||||||
if (id == 'exportAnnotations') {
|
if (id == 'exportAnnotations') {
|
||||||
|
|
@ -87,14 +98,8 @@ oml.ui.annotationPanel = function(options, self) {
|
||||||
},
|
},
|
||||||
change: function(data) {
|
change: function(data) {
|
||||||
var id = data.id;
|
var id = data.id;
|
||||||
if (data.id == 'showAnnotationUsers') {
|
console.log('change', data)
|
||||||
var value = data.checked[0].id;
|
if (id == 'show') {
|
||||||
oml.UI.set('showAnnotationUsers', value);
|
|
||||||
oml.$ui.viewer.renderAnnotations();
|
|
||||||
} else if (data.id == 'sortAnnotations') {
|
|
||||||
var value = data.checked[0].id;
|
|
||||||
oml.UI.set('sortAnnotations', value);
|
|
||||||
} else if (id == 'show') {
|
|
||||||
console.log('show', data)
|
console.log('show', data)
|
||||||
oml.UI.set({annotationsShow: data.checked[0].id});
|
oml.UI.set({annotationsShow: data.checked[0].id});
|
||||||
} else if (id == 'sort') {
|
} else if (id == 'sort') {
|
||||||
|
|
|
||||||
|
|
@ -206,6 +206,9 @@ oml.ui.viewer = function() {
|
||||||
if (sortKey == 'date') {
|
if (sortKey == 'date') {
|
||||||
sortKey = 'created'
|
sortKey = 'created'
|
||||||
}
|
}
|
||||||
|
if (sortKey == 'date') {
|
||||||
|
sortKey = 'created'
|
||||||
|
}
|
||||||
if (sortKey == 'quote') {
|
if (sortKey == 'quote') {
|
||||||
sortKey = 'text'
|
sortKey = 'text'
|
||||||
}
|
}
|
||||||
|
|
@ -213,7 +216,6 @@ oml.ui.viewer = function() {
|
||||||
loadAnnotations(function() {
|
loadAnnotations(function() {
|
||||||
that.renderAnnotations()
|
that.renderAnnotations()
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
annotations = Ox.sortBy(annotations, sortKey)
|
annotations = Ox.sortBy(annotations, sortKey)
|
||||||
oml.$ui.annotationFolder.empty();
|
oml.$ui.annotationFolder.empty();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue