[blam: 12/15] Revert "Use db4o as storage" and "Remove workaround for the XML storage"
- From: Carlos MartÃn Nieto <cmartin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [blam: 12/15] Revert "Use db4o as storage" and "Remove workaround for the XML storage"
- Date: Sat, 12 May 2012 23:52:00 +0000 (UTC)
commit e4155e378c3c214b2652b33dec68f944d5309da9
Author: Carlos MartÃn Nieto <carlos cmartin tk>
Date: Sun May 13 01:00:55 2012 +0200
Revert "Use db4o as storage" and "Remove workaround for the XML storage"
This reverts commit cc5d6b87bdeac3303dba4100af253eda3cff078d.
This reverts commit 7256a59dd128d2dc3753051538f475d0ec321e7f.
Using db4o was a nice experiment, but failed.
configure.in | 2 -
src/Application.cs | 2 +-
src/Channel.cs | 42 ++++++++------
src/ChannelCollection.cs | 2 +-
src/Defines.cs.in | 2 +-
src/Item.cs | 38 +++++++++++++
src/ItemList.cs | 8 +--
src/ItemStore.cs | 139 ++++++++++++++++++++++------------------------
src/Makefile.am | 2 +-
9 files changed, 135 insertions(+), 102 deletions(-)
---
diff --git a/configure.in b/configure.in
index 4fa43af..2059864 100644
--- a/configure.in
+++ b/configure.in
@@ -43,10 +43,8 @@ GTKSHARP_REQUIRED_VERSION=2.8.2
GNOMESHARP_REQUIRED_VERSION=2.16.1
GCONF_REQUIRED_VERSION=2.4
WEBKITSHARP_REQUIRED_VERSION=0.2
-DB4O_REQUIRED_VERSION=7.2
PKG_CHECK_MODULES(BLAM,
- db4o >= $DB4O_REQUIRED_VERSION
gtk-sharp-2.0 >= $GTKSHARP_REQUIRED_VERSION
webkit-sharp-1.0 >= $WEBKITSHARP_REQUIRED_VERSION
gconf-sharp-2.0 >= $GTKSHARP_REQUIRED_VERSION
diff --git a/src/Application.cs b/src/Application.cs
index ac21253..4b52e95 100644
--- a/src/Application.cs
+++ b/src/Application.cs
@@ -555,7 +555,7 @@ namespace Imendio.Blam {
SaveWindowState();
mainWindow.Hide();
mCollection.SaveToFile ();
- ItemStore.Close();
+ ItemStore.Save();
mCollection.StopAllThreads();
Quit();
diff --git a/src/Channel.cs b/src/Channel.cs
index e5cd17c..0508c90 100644
--- a/src/Channel.cs
+++ b/src/Channel.cs
@@ -42,6 +42,7 @@ namespace Imendio.Blam {
[XmlAttribute] public string http_username = "";
[XmlAttribute] public string http_password = "";
+ ItemStore store = null;
ArrayList item_list = null;
Object obj = new Object();
@@ -83,7 +84,7 @@ namespace Imendio.Blam {
lock(obj){
foreach (string id in item_list) {
if(id != null){
- item = ItemStore.Get(id);
+ item = store.Get(id);
if(item.Unread){
++unread;
}
@@ -104,7 +105,7 @@ namespace Imendio.Blam {
if(id == null){ /* TODO: Figure out why this happens */
continue;
}
- item = ItemStore.Get(id);
+ item = store.Get(id);
if(item != null && item.Unread && !item.Old){
++new_items;
}
@@ -143,6 +144,7 @@ namespace Imendio.Blam {
{
item_list = new ArrayList();
mIter = new Gtk.TreeIter();
+ store = ItemStore.GetInstance();
}
public Channel (string name, string url) : this()
@@ -153,7 +155,7 @@ namespace Imendio.Blam {
public Item GetItem (string id)
{
- return ItemStore.Get(id);
+ return store.Get(id);
}
public void Setup()
@@ -164,7 +166,7 @@ namespace Imendio.Blam {
if(id == null){
continue;
}
- Item item = ItemStore.Get(id);
+ Item item = store.Get(id);
if(item == null){
} else {
nlist.Add(id);
@@ -177,9 +179,10 @@ namespace Imendio.Blam {
public void RemoveItems()
{
+ ItemStore store = ItemStore.GetInstance();
lock(obj){
foreach(string id in item_list){
- ItemStore.Remove(id);
+ store.Remove(id);
}
}
}
@@ -195,10 +198,9 @@ namespace Imendio.Blam {
System.Console.WriteLine("null id {0} on {1}", id, Url);
continue;
}
- item = ItemStore.Get(id);
+ item = store.Get(id);
if (item.Unread) {
item.SetUnread (false);
- ItemStore.Update(item);
updated = true;
EmitUpdated();
}
@@ -228,24 +230,28 @@ namespace Imendio.Blam {
}
LastRefreshed = DateTime.Now;
-
/*
* The new item list is just the new list, so create it
* on the spot
*/
ArrayList nitems = new ArrayList();
foreach(SyndicationItem sitem in feed.Items){
- Item item = new Item(sitem);
- nitems.Add(item.Id);
+ nitems.Add(sitem.Id);
/* If didn't have it already, add it to the store */
- if(!item_list.Contains(item.Id))
- ItemStore.Add(item);
+ if(!item_list.Contains(sitem.Id)) {
+ store.Add(new Item(sitem));
+ } else {
+ if (sitem.Id == null)
+ continue;
+
+ store.Get(sitem.Id).Update(sitem);
+ }
}
/* Delete the items that are no longer in the feed */
foreach(string id in item_list){
if(!nitems.Contains(id)){
- ItemStore.Remove(id);
+ store.Remove(id);
}
}
@@ -257,7 +263,6 @@ namespace Imendio.Blam {
public void ItemUpdated(Item item)
{
- ItemStore.Update(item);
EmitUpdated();
}
@@ -268,24 +273,23 @@ namespace Imendio.Blam {
{
if(item_list.Contains(item.Id)){
/* In this case we only need to update */
- ItemStore.Get(item.Id).Update(item);
+ store.Get(item.Id).Update(item);
return;
}
- ItemStore.Add(item);
+ store.Add(item);
lock(obj){
item_list.Add(item.Id);
}
- ItemStore.Get(item.Id).Updated += ItemUpdated;
+ store.Get(item.Id).Updated += ItemUpdated;
}
/* Used to cross-mark as read */
public void MarkItemIdAsRead (string id)
{
- Item item = ItemStore.Get(id);
+ Item item = store.Get(id);
if (item.Unread) {
item.Unread = false;
- ItemStore.Update(item);
EmitUpdated();
}
}
diff --git a/src/ChannelCollection.cs b/src/ChannelCollection.cs
index 0e572ff..cf47451 100644
--- a/src/ChannelCollection.cs
+++ b/src/ChannelCollection.cs
@@ -342,7 +342,7 @@ namespace Imendio.Blam {
private bool WriteTimeoutHandler ()
{
SaveToFile ();
-// ItemStore.Save();
+ ItemStore.Save();
return false;
}
diff --git a/src/Defines.cs.in b/src/Defines.cs.in
index 9728067..af390ff 100644
--- a/src/Defines.cs.in
+++ b/src/Defines.cs.in
@@ -17,7 +17,7 @@ namespace Imendio.Blam {
public static string APP_DATADIR = DATADIR + "/blam";
public static string APP_HOMEDIR = Environment.GetEnvironmentVariable("HOME") + "/.gnome2/blam";
public static string APP_COLLECTION_FILE = "collection.xml";
- public static string APP_ITEMSTORE_FILE = "items.yap";
+ public static string APP_ITEMSTORE_FILE = "items.xml";
public static string GNOME_LOCALE_DIR = DATADIR + "/locale";
public static string THEME_DIR = APP_DATADIR + "/themes";
diff --git a/src/Item.cs b/src/Item.cs
index bcf4d0b..caaca62 100644
--- a/src/Item.cs
+++ b/src/Item.cs
@@ -38,6 +38,16 @@ namespace Imendio.Blam {
}
}
+ public void WriteExtensions()
+ {
+ ElementExtensions.Clear();
+ ElementExtensions.Add("unread", "blam", Unread);
+ ElementExtensions.Add("old", "blam", Old);
+ ElementExtensions.Add("permanent", "blam", Permanent);
+ ElementExtensions.Add("keywords", "blam", keywords);
+ ElementExtensions.Add("refcount", "blam", ref_cnt);
+ }
+
public int RefCount {
get {
return ref_cnt;
@@ -70,10 +80,38 @@ namespace Imendio.Blam {
/* Newlines aren't allowed in titles */
this.Title = new TextSyndicationContent(HtmlUtils.CollapseWhitespace(item.Title.Text));
+ if(item.Content != null){
+ /* The feed formatters only store the summary */
+ this.Summary = item.Content as TextSyndicationContent;
+ }
+
foreach(SyndicationElementExtension ext in item.ElementExtensions){
if(ext.OuterName == "encoded"){
this.Summary = new TextSyndicationContent(ext.GetObject<string>());
}
+
+ switch(ext.OuterNamespace){
+ /* Read our Item properties */
+ case "blam":
+ switch(ext.OuterName){
+ case "unread":
+ Unread = ext.GetObject<bool>();
+ break;
+ case "old":
+ Old = ext.GetObject<bool>();
+ break;
+ case "permanent":
+ Permanent = ext.GetObject<bool>();
+ break;
+ case "keywords":
+ Keywords = ext.GetObject<string>();
+ break;
+ case "refcount":
+ ref_cnt = ext.GetObject<int>();
+ break;
+ }
+ break;
+ }
}
}
diff --git a/src/ItemList.cs b/src/ItemList.cs
index d54d3af..86c4780 100644
--- a/src/ItemList.cs
+++ b/src/ItemList.cs
@@ -169,6 +169,7 @@ namespace Imendio.Blam {
public void UpdateList ()
{
((ListStore)this.Model).Clear();
+ ItemStore store = ItemStore.GetInstance();
if (this.channel == null) {
return;
}
@@ -176,7 +177,7 @@ namespace Imendio.Blam {
if(id == null){
continue;
}
- (Model as ListStore).AppendValues(ItemStore.Get(id));
+ (Model as ListStore).AppendValues(store.Get(id));
}
GLib.Timeout.Add (100, new GLib.TimeoutHandler (IdleScrollCb));
@@ -228,17 +229,14 @@ namespace Imendio.Blam {
lastTimeout = GLib.Timeout.Add(readTimeout, new GLib.TimeoutHandler (SetToRead));
} else {
item.SetUnread(false);
- ItemStore.Update(item);
}
}
}
private bool SetToRead()
{
- if(lastItem == GetSelected()){
+ if(lastItem == GetSelected())
lastItem.SetUnread(false);
- ItemStore.Update(lastItem);
- }
return false;
}
diff --git a/src/ItemStore.cs b/src/ItemStore.cs
index 834d5ff..e46841c 100644
--- a/src/ItemStore.cs
+++ b/src/ItemStore.cs
@@ -1,110 +1,73 @@
using System;
using System.IO;
-using System.Collections.Generic;
+using System.Collections;
using System.ServiceModel.Syndication;
using System.Xml;
using System.Xml.Serialization;
-using Db4objects.Db4o;
-using Db4objects.Db4o.Query;
namespace Imendio.Blam
{
public class ItemStore
{
- private IObjectContainer db;
- private System.Collections.Hashtable cache;
+ private Hashtable items;
static ItemStore instance = null;
static string itemfile = Defines.APP_HOMEDIR + "/" + Defines.APP_ITEMSTORE_FILE;
static string itemfile_tmp = Defines.APP_HOMEDIR + "/" + Defines.APP_ITEMSTORE_FILE + ".tmp";
+ private object db_lock = new object();
- public static Item Get(string id)
+ public Item Get(string id)
{
+ Item item;
+
if(id == null){
Console.Error.WriteLine("Tried to access item with null key");
return null;
}
- if(instance == null)
- Load();
-
- lock(instance.cache){
- if(instance.cache.ContainsKey(id))
- return instance.cache[id] as Item;
-
- IList<Item> items = instance.db.Query<Item>(delegate(Item item) {
- return item.Id == id;
- });
-
- if(items.Count > 1){
- Console.Error.WriteLine("There is more than one {0} in the DB", id);
- }
+ lock(db_lock){
+ item = items[id] as Item;
+ }
- if(items.Count > 0){
- instance.cache.Add(id, items[0]);
- return items[0];
- } else {
- return null;
- }
- }
+ return item;
}
- public static void Add(Item item)
+ public void Add(Item item)
{
if(item.Id == null){
Console.Error.WriteLine("Tried to add item with null key");
return;
}
- if(instance == null)
- Load();
-
- IList<Item> items = instance.db.Query<Item>(delegate(Item _item) {
- return _item.Id == item.Id;
- });
-
- if(items.Count > 0)
- item = items[0];
-
- /* The DB will overwrite or create a new entry */
- item.Grab();
- instance.db.Store(item);
+ lock(db_lock){
+ if(items.ContainsKey(item.Id)){
+ (items[item.Id] as Item).Grab();
+ return;
+ } else {
+ item.Grab();
+ items.Add(item.Id, item);
+ }
+ }
}
- public static void Update(Item item)
- {
- if(instance == null)
- Load();
-
- instance.db.Store(item);
- }
- public static void Remove(Item item)
+ public void Remove(Item item)
{
if(item == null){
- Console.Error.WriteLine("Tried to store null item");
return;
}
- if(instance == null)
- Load();
-
- if(item.RefCount == 1){
- instance.db.Delete(item);
- } else {
- item.Release();
- instance.db.Store(item);
- }
+ lock(db_lock){
+ item.Release();
+ if(item.RefCount == 0){
+ items.Remove(item.Id);
+ }
+ }
}
- public static void Remove(string id)
+ public void Remove(string id)
{
- IList<Item> items = instance.db.Query<Item>(delegate(Item _item) {
- return _item.Id == id;
- });
-
- if(items.Count > 0)
- Remove(items[0]);
- else
- Console.Error.WriteLine("Tried to remove non-existant item {0}", id);
+ lock(db_lock){
+ Remove(items[id] as Item);
+ }
}
public static ItemStore GetInstance()
@@ -119,17 +82,49 @@ namespace Imendio.Blam
private static void Load()
{
instance = new ItemStore();
- instance.cache = new System.Collections.Hashtable();
- instance.db = Db4oFactory.OpenFile(Db4oFactory.NewConfiguration(), itemfile);
+
+ XmlReader reader;
+ try{
+ reader = new XmlTextReader(itemfile);
+ } catch(Exception e){
+ Console.WriteLine("Can't open item db: {0}", e.Message);
+ return;
+ }
+
+ Console.WriteLine("about to format");
+ SyndicationFeed feed = SyndicationFeed.Load(reader);
+ foreach(SyndicationItem item in feed.Items){
+ instance.items.Add(item.Id, new Item(item));
+ }
}
- public static void Close()
+ public static void Save()
{
if(instance == null){
return;
}
- instance.db.Close();
+ Item[] items;
+
+ lock(instance.db_lock){
+ foreach(Item item in instance.items.Values){
+ item.WriteExtensions();
+ }
+ items = new Item[instance.items.Count];
+ instance.items.Values.CopyTo(items, 0);
+ }
+ XmlWriter writer = XmlWriter.Create(itemfile_tmp);
+ SyndicationFeed sf = new SyndicationFeed(items);
+ Atom10FeedFormatter fmtr = sf.GetAtom10Formatter();
+ fmtr.WriteTo(writer);
+ writer.Close();
+ File.Delete(itemfile);
+ File.Move(itemfile_tmp, itemfile);
}
+
+ private ItemStore ()
+ {
+ items = new Hashtable();
+ }
}
}
diff --git a/src/Makefile.am b/src/Makefile.am
index 3e9aa1e..a239998 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,7 +10,7 @@ RESOURCES = \
ASSEMBLIES = \
-r:System.Web \
-r:Mono.Posix \
- -r:System.ServiceModel.Web
+ -r:System.ServiceModel
BLAM_CSFILES = Application.cs \
ChannelDialog.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]