- Workaround for apparent async DB call brokenness in autocomplete -- and only occasionally permanently hang Firefox
- Restore (non-asynchronous) Fx3.0 support
This commit is contained in:
parent
76cab84373
commit
ae88cbd0ce
|
@ -48,6 +48,7 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam, p
|
||||||
this._result = result;
|
this._result = result;
|
||||||
this._results = [];
|
this._results = [];
|
||||||
this._listener = listener;
|
this._listener = listener;
|
||||||
|
this._cancelled = false;
|
||||||
|
|
||||||
this._zotero.debug("Starting autocomplete search of type '"
|
this._zotero.debug("Starting autocomplete search of type '"
|
||||||
+ searchParam + "'" + " with string '" + searchString + "'");
|
+ searchParam + "'" + " with string '" + searchString + "'");
|
||||||
|
@ -72,7 +73,7 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam, p
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'tag':
|
case 'tag':
|
||||||
var sql = "SELECT DISTINCT name, NULL FROM tags WHERE name LIKE ?";
|
var sql = "SELECT DISTINCT name AS val, NULL AS comment FROM tags WHERE name LIKE ?";
|
||||||
var sqlParams = [searchString + '%'];
|
var sqlParams = [searchString + '%'];
|
||||||
if (extra){
|
if (extra){
|
||||||
sql += " AND name NOT IN (SELECT name FROM tags WHERE tagID IN ("
|
sql += " AND name NOT IN (SELECT name FROM tags WHERE tagID IN ("
|
||||||
|
@ -100,18 +101,18 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam, p
|
||||||
if (fieldMode==2)
|
if (fieldMode==2)
|
||||||
{
|
{
|
||||||
var sql = "SELECT DISTINCT CASE fieldMode WHEN 1 THEN lastName "
|
var sql = "SELECT DISTINCT CASE fieldMode WHEN 1 THEN lastName "
|
||||||
+ "WHEN 0 THEN firstName || ' ' || lastName END AS name, NULL "
|
+ "WHEN 0 THEN firstName || ' ' || lastName END AS val, NULL AS comment "
|
||||||
+ "FROM creators NATURAL JOIN creatorData WHERE CASE fieldMode "
|
+ "FROM creators NATURAL JOIN creatorData WHERE CASE fieldMode "
|
||||||
+ "WHEN 1 THEN lastName "
|
+ "WHEN 1 THEN lastName "
|
||||||
+ "WHEN 0 THEN firstName || ' ' || lastName END "
|
+ "WHEN 0 THEN firstName || ' ' || lastName END "
|
||||||
+ "LIKE ? ORDER BY name";
|
+ "LIKE ? ORDER BY val";
|
||||||
var sqlParams = searchString + '%';
|
var sqlParams = searchString + '%';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var sql = "SELECT DISTINCT ";
|
var sql = "SELECT DISTINCT ";
|
||||||
if (fieldMode==1){
|
if (fieldMode==1){
|
||||||
sql += "lastName AS name, creatorID || '-1' AS creatorID";
|
sql += "lastName AS val, creatorID || '-1' AS comment";
|
||||||
}
|
}
|
||||||
// Retrieve the matches in the specified field
|
// Retrieve the matches in the specified field
|
||||||
// as well as any full names using the name
|
// as well as any full names using the name
|
||||||
|
@ -123,10 +124,10 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam, p
|
||||||
// - 2 means it uses both
|
// - 2 means it uses both
|
||||||
else {
|
else {
|
||||||
sql += "CASE WHEN firstName='' OR firstName IS NULL THEN lastName "
|
sql += "CASE WHEN firstName='' OR firstName IS NULL THEN lastName "
|
||||||
+ "ELSE lastName || ', ' || firstName END AS name, "
|
+ "ELSE lastName || ', ' || firstName END AS val, "
|
||||||
+ "creatorID || '-' || CASE "
|
+ "creatorID || '-' || CASE "
|
||||||
+ "WHEN (firstName = '' OR firstName IS NULL) THEN 1 "
|
+ "WHEN (firstName = '' OR firstName IS NULL) THEN 1 "
|
||||||
+ "ELSE 2 END AS creatorID";
|
+ "ELSE 2 END AS comment";
|
||||||
}
|
}
|
||||||
|
|
||||||
var fromSQL = " FROM creators NATURAL JOIN creatorData "
|
var fromSQL = " FROM creators NATURAL JOIN creatorData "
|
||||||
|
@ -145,11 +146,11 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam, p
|
||||||
// as well (i.e. "Shakespeare"), and group to collapse repeats
|
// as well (i.e. "Shakespeare"), and group to collapse repeats
|
||||||
if (fieldMode!=1){
|
if (fieldMode!=1){
|
||||||
sql = "SELECT * FROM (" + sql + " UNION SELECT DISTINCT "
|
sql = "SELECT * FROM (" + sql + " UNION SELECT DISTINCT "
|
||||||
+ searchParts[2] + " AS name, creatorID || '-1' AS creatorID"
|
+ searchParts[2] + " AS val, creatorID || '-1' AS comment"
|
||||||
+ fromSQL + ") GROUP BY name";
|
+ fromSQL + ") GROUP BY val";
|
||||||
}
|
}
|
||||||
|
|
||||||
sql += " ORDER BY name";
|
sql += " ORDER BY val";
|
||||||
}
|
}
|
||||||
|
|
||||||
statement = this._zotero.DB.getStatement(sql, sqlParams);
|
statement = this._zotero.DB.getStatement(sql, sqlParams);
|
||||||
|
@ -157,7 +158,7 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam, p
|
||||||
|
|
||||||
case 'dateModified':
|
case 'dateModified':
|
||||||
case 'dateAdded':
|
case 'dateAdded':
|
||||||
var sql = "SELECT DISTINCT DATE(" + searchParam + ", 'localtime'), NULL FROM items "
|
var sql = "SELECT DISTINCT DATE(" + searchParam + ", 'localtime') AS val, NULL AS comment FROM items "
|
||||||
+ "WHERE " + searchParam + " LIKE ? ORDER BY " + searchParam;
|
+ "WHERE " + searchParam + " LIKE ? ORDER BY " + searchParam;
|
||||||
statement = this._zotero.DB.getStatement(sql, searchString + '%');
|
statement = this._zotero.DB.getStatement(sql, searchString + '%');
|
||||||
break;
|
break;
|
||||||
|
@ -165,7 +166,7 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam, p
|
||||||
case 'accessDate':
|
case 'accessDate':
|
||||||
var fieldID = this._zotero.ItemFields.getID('accessDate');
|
var fieldID = this._zotero.ItemFields.getID('accessDate');
|
||||||
|
|
||||||
var sql = "SELECT DISTINCT DATE(value, 'localtime'), NULL FROM itemData "
|
var sql = "SELECT DISTINCT DATE(value, 'localtime') AS val, NULL AS comment FROM itemData "
|
||||||
+ "WHERE fieldID=? AND value LIKE ? ORDER BY value";
|
+ "WHERE fieldID=? AND value LIKE ? ORDER BY value";
|
||||||
statement = this._zotero.DB.getStatement(sql, [fieldID, searchString + '%']);
|
statement = this._zotero.DB.getStatement(sql, [fieldID, searchString + '%']);
|
||||||
break;
|
break;
|
||||||
|
@ -183,7 +184,7 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam, p
|
||||||
// use the user part of the multipart field
|
// use the user part of the multipart field
|
||||||
var valueField = searchParam=='date' ? 'SUBSTR(value, 12, 100)' : 'value';
|
var valueField = searchParam=='date' ? 'SUBSTR(value, 12, 100)' : 'value';
|
||||||
|
|
||||||
var sql = "SELECT DISTINCT " + valueField + ", NULL "
|
var sql = "SELECT DISTINCT " + valueField + " AS val, NULL AS comment "
|
||||||
+ "FROM itemData NATURAL JOIN itemDataValues "
|
+ "FROM itemData NATURAL JOIN itemDataValues "
|
||||||
+ "WHERE fieldID=?1 AND " + valueField
|
+ "WHERE fieldID=?1 AND " + valueField
|
||||||
+ " LIKE ?2 "
|
+ " LIKE ?2 "
|
||||||
|
@ -198,6 +199,31 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam, p
|
||||||
statement = this._zotero.DB.getStatement(sql, sqlParams);
|
statement = this._zotero.DB.getStatement(sql, sqlParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._zotero.isFx30) {
|
||||||
|
var rows = this._zotero.DB.query(sql, sqlParams);
|
||||||
|
var results = [];
|
||||||
|
var comments = [];
|
||||||
|
for each(var row in rows) {
|
||||||
|
results.push(row.val);
|
||||||
|
let comment = row.comment;
|
||||||
|
if (comment) {
|
||||||
|
comments.push(comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.updateResults(results, comments);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
this._zotero.DB._connection.setProgressHandler(5000, {
|
||||||
|
onProgress: function (connection) {
|
||||||
|
if (self._cancelled) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.pendingStatement = statement.executeAsync({
|
this.pendingStatement = statement.executeAsync({
|
||||||
handleResult: function (storageResultSet) {
|
handleResult: function (storageResultSet) {
|
||||||
self._zotero.debug("Handling autocomplete results");
|
self._zotero.debug("Handling autocomplete results");
|
||||||
|
@ -226,7 +252,7 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam, p
|
||||||
},
|
},
|
||||||
|
|
||||||
handleError: function (e) {
|
handleError: function (e) {
|
||||||
Components.utils.reportError(e.message);
|
//Components.utils.reportError(e.message);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleCompletion: function (reason) {
|
handleCompletion: function (reason) {
|
||||||
|
@ -295,10 +321,11 @@ ZoteroAutoComplete.prototype.updateResults = function (results, comments, ongoin
|
||||||
|
|
||||||
ZoteroAutoComplete.prototype.stopSearch = function(){
|
ZoteroAutoComplete.prototype.stopSearch = function(){
|
||||||
if (this.pendingStatement) {
|
if (this.pendingStatement) {
|
||||||
// DEBUG: This appears to take as long as letting the query complete
|
|
||||||
this._zotero.debug('Stopping autocomplete search');
|
this._zotero.debug('Stopping autocomplete search');
|
||||||
this.pendingStatement.cancel();
|
// This appears to take as long as letting the query complete,
|
||||||
this._zotero.debug('Search cancelled');
|
// so we flag instead and abort from the progress handler
|
||||||
|
//this.pendingStatement.cancel();
|
||||||
|
this._cancelled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user