Cache parsed database

cusax-fix
Ingo Bauersachs 13 years ago
parent 5192902101
commit 471d31bb3e

@ -50,12 +50,15 @@ public ThunderbirdContactQuery(ThunderbirdContactSourceService owner,
@Override
protected void run()
{
String file = super.getContactSource().getFilename();
String filename = super.getContactSource().getFilename();
File file = new File(filename);
try
{
if (file.lastModified() > getContactSource().lastDatabaseFileChange)
{
// parse the Thunderbird Mork database
InputStreamReader sr =
new InputStreamReader(new FileInputStream(file));
new InputStreamReader(new FileInputStream(filename));
MorkDocument md = new MorkDocument(sr);
sr.close();
@ -86,9 +89,9 @@ protected void run()
}
}
// The additional rows at the root-level update/replace the ones in
// the tables. There's usually neither a table nor a scope defined,
// so lets just use the default.
// The additional rows at the root-level update/replace the ones
// in the tables. There's usually neither a table nor a scope
// defined, so lets just use the default.
String defaultScope = md.getDicts().get(0).dereference("^80");
for (Row r : md.getRows())
{
@ -115,12 +118,19 @@ protected void run()
table.put(rowId, r);
}
super.getContactSource().database = db;
super.getContactSource().defaultScope = defaultScope;
super.getContactSource().lastDatabaseFileChange =
file.lastModified();
}
// okay, "transactions" are applied, now perform the search
for (Entry<String, Map<String, Row>> table : db.entrySet())
for (Entry<String, Map<String, Row>> table
: super.getContactSource().database.entrySet())
{
for (Map.Entry<String, Row> e : table.getValue().entrySet())
{
if (e.getKey().endsWith(defaultScope))
if (e.getKey().endsWith(getContactSource().defaultScope))
{
readEntry(e.getValue());
}

@ -6,10 +6,12 @@
*/
package net.java.sip.communicator.plugin.thunderbird;
import java.util.Map;
import java.util.regex.*;
import org.jitsi.service.configuration.*;
import mork.Row;
import net.java.sip.communicator.service.contactsource.*;
/**
@ -72,6 +74,19 @@ public class ThunderbirdContactSourceService
/** Value of property {@link #PNAME_PREFIX} */
private String prefix;
/** Date/time when the Thunderbird database file was last changed. */
long lastDatabaseFileChange = 0;
/**
* The parsed Thunderbird database. This field is used as a cache and set by
* the query. It is re-set when the file date is newer than
* {@link #lastDatabaseFileChange}
*/
Map<String, Map<String, Row>> database;
/** Name of the default namespace in the Thunderbird database. */
String defaultScope;
/**
* Creates a new instance of this class.
*

Loading…
Cancel
Save