[Xfce4-commits] <postler:master> Client, Dexter, and Index should be singletons
Christian Dywan
noreply at xfce.org
Fri May 27 20:32:05 CEST 2011
Updating branch refs/heads/master
to 72659e85c0c69ab877a017f1d521d3a6b8f6cc52 (commit)
from 6d0948be12de384ed3030250b7b6037e39f9c71c (commit)
commit 72659e85c0c69ab877a017f1d521d3a6b8f6cc52
Author: Christian Dywan <christian at twotoasts.de>
Date: Wed May 25 18:30:56 2011 +0200
Client, Dexter, and Index should be singletons
There's no benefit in multiple instances of a DBus proxy
or an sqlite dabatase, but the overhead is harmful.
postler/dexter.vala | 2 ++
postler/postler-client.vala | 4 +++-
postler/postler-index.vala | 13 ++++++++-----
postler/postler-service.vala | 24 ++++++++++++++----------
4 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/postler/dexter.vala b/postler/dexter.vala
index ddde325..a813b5e 100644
--- a/postler/dexter.vala
+++ b/postler/dexter.vala
@@ -22,6 +22,8 @@ namespace Dexter {
public class Dexter : Object {
DexterService? service = null;
public Dexter () {
+ if (service != null)
+ return;
try {
service = Bus.get_proxy_sync (BusType.SESSION,
"org.elementary.dexterserver",
diff --git a/postler/postler-client.vala b/postler/postler-client.vala
index d07a782..af356f4 100644
--- a/postler/postler-client.vala
+++ b/postler/postler-client.vala
@@ -26,9 +26,11 @@ namespace Postler {
}
public class Client : Object {
- PostlerClient client;
+ static PostlerClient? client = null;
public Client () {
+ if (client != null)
+ return;
try {
client = Bus.get_proxy_sync (BusType.SESSION,
"org.elementary.Postler",
diff --git a/postler/postler-index.vala b/postler/postler-index.vala
index 0e786bc..cc97241 100644
--- a/postler/postler-index.vala
+++ b/postler/postler-index.vala
@@ -11,17 +11,20 @@
namespace Postler {
public class Index : GLib.Object, GLib.Initable {
- Sqlite.Database database;
- Sqlite.Statement? statement_insert = null;
- Sqlite.Statement? statement_get = null;
- Sqlite.Statement? statement_list = null;
- Sqlite.Statement? statement_unread = null;
+ static Sqlite.Database? database = null;
+ static Sqlite.Statement? statement_insert = null;
+ static Sqlite.Statement? statement_get = null;
+ static Sqlite.Statement? statement_list = null;
+ static Sqlite.Statement? statement_unread = null;
bool init (GLib.Cancellable? cancellable = null) throws GLib.Error {
return true;
}
public Index () throws GLib.Error {
+ if (database != null)
+ return;
+
unowned string data_dir = Environment.get_user_data_dir ();
string data_path = data_dir + "/" + Config.PACKAGE_NAME + "/mail/";
if (Sqlite.Database.open (data_path + "index.db", out database) != Sqlite.OK)
diff --git a/postler/postler-service.vala b/postler/postler-service.vala
index 685dac5..0efc401 100644
--- a/postler/postler-service.vala
+++ b/postler/postler-service.vala
@@ -151,6 +151,15 @@ namespace Postler {
#endif
bool new_message_timer () {
+ if (index == null) {
+ try {
+ index = new Index ();
+ setup_index (index, new Accounts ());
+ }
+ catch (GLib.Error error) {
+ GLib.warning (_("Index can't be setup: %s"), error.message);
+ }
+ }
receive ("");
return true;
}
@@ -206,7 +215,8 @@ namespace Postler {
var accounts = new Accounts ();
try {
- setup_index (get_index (), accounts);
+ index = new Index ();
+ GLib.Idle.add (() => { setup_index (index, accounts); return false; });
}
catch (GLib.Error error) {
GLib.warning (_("Index can't be setup: %s"), error.message);
@@ -298,22 +308,16 @@ namespace Postler {
}
}
- Index get_index () throws GLib.Error {
- if (index == null)
- index = new Index ();
- return index;
- }
-
public int64 unread_messages (string uri) throws GLib.Error {
- return get_index ().unread_messages (uri);
+ return index.unread_messages (uri);
}
public GLib.HashTable<string,Variant> get_message (string uri) throws GLib.Error {
- return get_index ().get_message (uri).to_hash_table ();
+ return index.get_message (uri).to_hash_table ();
}
public string[] get_messages (string uri) throws GLib.Error {
- var messages = get_index ().get_messages (uri);
+ var messages = index.get_messages (uri);
string[] uris = {};
foreach (var message in messages)
uris += message.uri;
More information about the Xfce4-commits
mailing list