more Caching

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1965 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 19 years ago
parent 918445a2f4
commit 44d72f06c4

@ -48,7 +48,6 @@
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -56,8 +55,8 @@ import de.anomic.data.bookmarksDB;
import de.anomic.data.listManager; import de.anomic.data.listManager;
import de.anomic.data.bookmarksDB.Tag; import de.anomic.data.bookmarksDB.Tag;
import de.anomic.http.httpHeader; import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.plasma.plasmaCrawlLURL; import de.anomic.plasma.plasmaCrawlLURL;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverObjects; import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
@ -152,7 +151,7 @@ public class Bookmarks {
prop.put("mode_title", bookmark.getTitle()); prop.put("mode_title", bookmark.getTitle());
prop.put("mode_description", bookmark.getDescription()); prop.put("mode_description", bookmark.getDescription());
prop.put("mode_url", bookmark.getUrl()); prop.put("mode_url", bookmark.getUrl());
prop.put("mode_tags", bookmark.getTags()); prop.put("mode_tags", bookmark.getTagsString());
if (bookmark.getPublic()) { if (bookmark.getPublic()) {
prop.put("mode_public", 1); prop.put("mode_public", 1);
} else { } else {
@ -221,7 +220,7 @@ public class Bookmarks {
count++; count++;
} }
count=0; count=0;
ArrayList tags; HashSet tags;
Iterator tagsIt; Iterator tagsIt;
int tagCount; int tagCount;
while(count<max_count && it.hasNext()){ while(count<max_count && it.hasNext()){
@ -233,7 +232,7 @@ public class Bookmarks {
prop.put("bookmarks_"+count+"_public", (bookmark.getPublic()? 1:0)); prop.put("bookmarks_"+count+"_public", (bookmark.getPublic()? 1:0));
//List Tags. //List Tags.
tags=bookmark.getTagsList(); tags=bookmark.getTags();
tagsIt=tags.iterator(); tagsIt=tags.iterator();
tagCount=0; tagCount=0;
while(tagsIt.hasNext()){ while(tagsIt.hasNext()){

@ -78,7 +78,7 @@ public class all {
prop.putNoHTML("posts_"+count+"_md5", serverCodings.encodeMD5Hex(bookmark.getUrl())); prop.putNoHTML("posts_"+count+"_md5", serverCodings.encodeMD5Hex(bookmark.getUrl()));
date=new Date(bookmark.getTimeStamp()); date=new Date(bookmark.getTimeStamp());
prop.putNoHTML("posts_"+count+"_time", bookmarksDB.dateToiso8601(date)); prop.putNoHTML("posts_"+count+"_time", bookmarksDB.dateToiso8601(date));
prop.putNoHTML("posts_"+count+"_tags", bookmark.getTags().replaceAll(","," ")); prop.putNoHTML("posts_"+count+"_tags", bookmark.getTagsString().replaceAll(","," "));
count++; count++;
} }
prop.put("posts", count); prop.put("posts", count);

@ -282,14 +282,14 @@ public class bookmarksDB {
String[] tags; String[] tags;
while(it.hasNext()){ while(it.hasNext()){
bookmark=(Bookmark) it.next(); bookmark=(Bookmark) it.next();
tags = bookmark.getTags().split(","); tags = bookmark.getTagsString().split(",");
tag=null; tag=null;
for(int i=0;i<tags.length;i++){ for(int i=0;i<tags.length;i++){
tag=getTag(tagHash(tags[i])); tag=getTag(tagHash(tags[i]));
if(tag==null){ if(tag==null){
tag=new Tag(tags[i]); tag=new Tag(tags[i]);
} }
tag.add(bookmark.getUrlHash()); tag.addUrl(bookmark.getUrlHash());
saveTag(tag); saveTag(tag);
} }
} }
@ -350,7 +350,7 @@ public class bookmarksDB {
HashSet tags; HashSet tags;
while (it.hasNext()) { while (it.hasNext()) {
bookmark = getBookmark((String) it.next()); bookmark = getBookmark((String) it.next());
tags = listManager.string2hashset(bookmark.getTags()); tags = bookmark.getTags();
tags.remove(oldName); //this will fail, if upper/lowercase is not matching tags.remove(oldName); //this will fail, if upper/lowercase is not matching
tags.add(newName); tags.add(newName);
bookmark.setTags(tags, true); bookmark.setTags(tags, true);
@ -435,11 +435,12 @@ public class bookmarksDB {
public boolean removeBookmark(String urlHash){ public boolean removeBookmark(String urlHash){
Bookmark bookmark = getBookmark(urlHash); Bookmark bookmark = getBookmark(urlHash);
if(bookmark == null) return false; //does not exist if(bookmark == null) return false; //does not exist
String[] tags = bookmark.getTags().split(","); HashSet tags = bookmark.getTags();
bookmarksDB.Tag tag=null; bookmarksDB.Tag tag=null;
for(int i=0;i<tags.length;i++){ Iterator it=tags.iterator();
tag=getTag(tagHash(tags[i])); while(it.hasNext()){
if(tag !=null){ tag=getTag((String) it.next());
if(tag!=null){
tag.delete(urlHash); tag.delete(urlHash);
saveTag(tag); saveTag(tag);
} }
@ -643,7 +644,7 @@ public class bookmarksDB {
} }
return false; return false;
} }
public void add(String urlHash){ public void addUrl(String urlHash){
urlHashes.add(urlHash); urlHashes.add(urlHash);
} }
public void delete(String urlHash){ public void delete(String urlHash){
@ -727,9 +728,13 @@ public class bookmarksDB {
public static final String BOOKMARK_TIMESTAMP="bookmarkTimestamp"; public static final String BOOKMARK_TIMESTAMP="bookmarkTimestamp";
private String urlHash; private String urlHash;
private Map mem; private Map mem;
private HashSet tags;
private long timestamp;
public Bookmark(String urlHash, Map map){ public Bookmark(String urlHash, Map map){
this.urlHash=urlHash; this.urlHash=urlHash;
this.mem=map; this.mem=map;
tags=listManager.string2hashset((String) map.get(BOOKMARK_TAGS));
loadTimestamp();
} }
public Bookmark(String url){ public Bookmark(String url){
if(!url.toLowerCase().startsWith("http://")){ if(!url.toLowerCase().startsWith("http://")){
@ -738,45 +743,55 @@ public class bookmarksDB {
this.urlHash=plasmaURL.urlHash(url); this.urlHash=plasmaURL.urlHash(url);
mem=new HashMap(); mem=new HashMap();
mem.put(BOOKMARK_URL, url); mem.put(BOOKMARK_URL, url);
this.timestamp=System.currentTimeMillis();
tags=new HashSet();
Bookmark oldBm=getBookmark(this.urlHash); Bookmark oldBm=getBookmark(this.urlHash);
if(oldBm!=null && oldBm.mem.containsKey(BOOKMARK_TIMESTAMP)){ if(oldBm!=null && oldBm.mem.containsKey(BOOKMARK_TIMESTAMP)){
mem.put(BOOKMARK_TIMESTAMP, oldBm.mem.get(BOOKMARK_TIMESTAMP)); //preserve timestamp on edit mem.put(BOOKMARK_TIMESTAMP, oldBm.mem.get(BOOKMARK_TIMESTAMP)); //preserve timestamp on edit
}else{ }else{
mem.put(BOOKMARK_TIMESTAMP, String.valueOf(System.currentTimeMillis())); mem.put(BOOKMARK_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
} }
bookmarksDate bmDate=getDate((String) mem.get(BOOKMARK_TIMESTAMP)); bookmarksDate bmDate=getDate((String) mem.get(BOOKMARK_TIMESTAMP));
bmDate.add(this.urlHash); bmDate.add(this.urlHash);
bmDate.setDatesTable(); bmDate.setDatesTable();
removeBookmark(this.urlHash); //prevent empty tags removeBookmark(this.urlHash); //prevent empty tags
} }
public Bookmark(String urlHash, URL url){ public Bookmark(String urlHash, URL url){
this.urlHash=urlHash; this.urlHash=urlHash;
mem=new HashMap(); mem=new HashMap();
mem.put(BOOKMARK_URL, url.toString()); mem.put(BOOKMARK_URL, url.toString());
tags=new HashSet();
timestamp=System.currentTimeMillis();
} }
public Bookmark(String urlHash, String url){ public Bookmark(String urlHash, String url){
this.urlHash=urlHash; this.urlHash=urlHash;
mem=new HashMap(); mem=new HashMap();
mem.put(BOOKMARK_URL, url); mem.put(BOOKMARK_URL, url);
tags=new HashSet();
timestamp=System.currentTimeMillis();
} }
public Map getMap(){ public Map getMap(){
mem.put(BOOKMARK_TAGS, listManager.hashset2string(tags));
mem.put(BOOKMARK_TIMESTAMP, String.valueOf(this.timestamp));
return mem; return mem;
} }
private void loadTimestamp(){
if(this.mem.containsKey(BOOKMARK_TIMESTAMP))
this.timestamp=Long.parseLong((String)mem.get(BOOKMARK_TIMESTAMP));
}
public String getUrlHash(){ public String getUrlHash(){
return urlHash; return urlHash;
} }
public String getUrl(){ public String getUrl(){
return (String) this.mem.get(BOOKMARK_URL); return (String) this.mem.get(BOOKMARK_URL);
} }
public String getTags(){ public HashSet getTags(){
if(this.mem.containsKey(BOOKMARK_TAGS)){ return tags;
return (String)this.mem.get(BOOKMARK_TAGS);
}
return "";
} }
public ArrayList getTagsList(){ public String getTagsString(){
return listManager.string2arraylist(this.getTags()); return listManager.hashset2string(getTags());
} }
public String getDescription(){ public String getDescription(){
if(this.mem.containsKey(BOOKMARK_DESCRIPTION)){ if(this.mem.containsKey(BOOKMARK_DESCRIPTION)){
@ -809,14 +824,7 @@ public class bookmarksDB {
//setBookmarksTable(); //setBookmarksTable();
} }
public void addTag(String tag){ public void addTag(String tag){
HashSet tags;
if(!mem.containsKey(BOOKMARK_TAGS)){
tags=new HashSet();
}else{
tags=listManager.string2hashset((String) mem.get(BOOKMARK_TAGS));
}
tags.add(tag); tags.add(tag);
this.setTags(tags, true);
} }
/** /**
* set the Tags of the bookmark, and write them into the tags table. * set the Tags of the bookmark, and write them into the tags table.
@ -831,7 +839,7 @@ public class bookmarksDB {
* @param local sets, whether the updated tags should be stored to tagsDB * @param local sets, whether the updated tags should be stored to tagsDB
*/ */
public void setTags(HashSet tags, boolean local){ public void setTags(HashSet tags, boolean local){
mem.put(BOOKMARK_TAGS, listManager.hashset2string(tags)); tags.addAll(tags);
Iterator it=tags.iterator(); Iterator it=tags.iterator();
while(it.hasNext()){ while(it.hasNext()){
String tagName=(String) it.next(); String tagName=(String) it.next();
@ -839,7 +847,7 @@ public class bookmarksDB {
if(tag == null){ if(tag == null){
tag=new Tag(tagName); tag=new Tag(tagName);
} }
tag.add(getUrlHash()); tag.addUrl(getUrlHash());
if(local){ if(local){
saveTag(tag); saveTag(tag);
} }
@ -847,14 +855,10 @@ public class bookmarksDB {
} }
public long getTimeStamp(){ public long getTimeStamp(){
if(mem.containsKey(BOOKMARK_TIMESTAMP)){ return timestamp;
return Long.parseLong((String)mem.get(BOOKMARK_TIMESTAMP));
}else{
return 0;
}
} }
public void setTimeStamp(long timestamp){ public void setTimeStamp(long ts){
this.mem.put(BOOKMARK_TIMESTAMP, String.valueOf(timestamp)); this.timestamp=ts;
} }
} }
public class tagIterator implements Iterator{ public class tagIterator implements Iterator{
@ -943,10 +947,21 @@ public class bookmarksDB {
Bookmark bm1=getBookmark((String)obj1); Bookmark bm1=getBookmark((String)obj1);
Bookmark bm2=getBookmark((String)obj2); Bookmark bm2=getBookmark((String)obj2);
//XXX: what happens, if there is a big difference? (to much for int) //XXX: what happens, if there is a big difference? (to much for int)
if(this.newestFirst){ /*if(this.newestFirst){
return (new Long(bm2.getTimeStamp() - bm1.getTimeStamp())).intValue(); return (new Long(bm2.getTimeStamp() - bm1.getTimeStamp())).intValue();
}else{ }else{
return (new Long(bm1.getTimeStamp() - bm2.getTimeStamp())).intValue(); return (new Long(bm1.getTimeStamp() - bm2.getTimeStamp())).intValue();
}*/
if(this.newestFirst){
if(bm2.getTimeStamp() - bm1.getTimeStamp() >0)
return 1;
else
return -1;
}else{
if(bm1.getTimeStamp() - bm2.getTimeStamp() >0)
return 1;
else
return -1;
} }
} }
} }

Loading…
Cancel
Save