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

@ -78,7 +78,7 @@ public class all {
prop.putNoHTML("posts_"+count+"_md5", serverCodings.encodeMD5Hex(bookmark.getUrl()));
date=new Date(bookmark.getTimeStamp());
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++;
}
prop.put("posts", count);

@ -282,14 +282,14 @@ public class bookmarksDB {
String[] tags;
while(it.hasNext()){
bookmark=(Bookmark) it.next();
tags = bookmark.getTags().split(",");
tags = bookmark.getTagsString().split(",");
tag=null;
for(int i=0;i<tags.length;i++){
tag=getTag(tagHash(tags[i]));
if(tag==null){
tag=new Tag(tags[i]);
}
tag.add(bookmark.getUrlHash());
tag.addUrl(bookmark.getUrlHash());
saveTag(tag);
}
}
@ -350,7 +350,7 @@ public class bookmarksDB {
HashSet tags;
while (it.hasNext()) {
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.add(newName);
bookmark.setTags(tags, true);
@ -435,11 +435,12 @@ public class bookmarksDB {
public boolean removeBookmark(String urlHash){
Bookmark bookmark = getBookmark(urlHash);
if(bookmark == null) return false; //does not exist
String[] tags = bookmark.getTags().split(",");
HashSet tags = bookmark.getTags();
bookmarksDB.Tag tag=null;
for(int i=0;i<tags.length;i++){
tag=getTag(tagHash(tags[i]));
if(tag !=null){
Iterator it=tags.iterator();
while(it.hasNext()){
tag=getTag((String) it.next());
if(tag!=null){
tag.delete(urlHash);
saveTag(tag);
}
@ -643,7 +644,7 @@ public class bookmarksDB {
}
return false;
}
public void add(String urlHash){
public void addUrl(String urlHash){
urlHashes.add(urlHash);
}
public void delete(String urlHash){
@ -727,9 +728,13 @@ public class bookmarksDB {
public static final String BOOKMARK_TIMESTAMP="bookmarkTimestamp";
private String urlHash;
private Map mem;
private HashSet tags;
private long timestamp;
public Bookmark(String urlHash, Map map){
this.urlHash=urlHash;
this.mem=map;
tags=listManager.string2hashset((String) map.get(BOOKMARK_TAGS));
loadTimestamp();
}
public Bookmark(String url){
if(!url.toLowerCase().startsWith("http://")){
@ -738,45 +743,55 @@ public class bookmarksDB {
this.urlHash=plasmaURL.urlHash(url);
mem=new HashMap();
mem.put(BOOKMARK_URL, url);
this.timestamp=System.currentTimeMillis();
tags=new HashSet();
Bookmark oldBm=getBookmark(this.urlHash);
if(oldBm!=null && oldBm.mem.containsKey(BOOKMARK_TIMESTAMP)){
mem.put(BOOKMARK_TIMESTAMP, oldBm.mem.get(BOOKMARK_TIMESTAMP)); //preserve timestamp on edit
}else{
mem.put(BOOKMARK_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
}
bookmarksDate bmDate=getDate((String) mem.get(BOOKMARK_TIMESTAMP));
bmDate.add(this.urlHash);
bmDate.setDatesTable();
removeBookmark(this.urlHash); //prevent empty tags
bookmarksDate bmDate=getDate((String) mem.get(BOOKMARK_TIMESTAMP));
bmDate.add(this.urlHash);
bmDate.setDatesTable();
removeBookmark(this.urlHash); //prevent empty tags
}
public Bookmark(String urlHash, URL url){
this.urlHash=urlHash;
mem=new HashMap();
mem.put(BOOKMARK_URL, url.toString());
tags=new HashSet();
timestamp=System.currentTimeMillis();
}
public Bookmark(String urlHash, String url){
this.urlHash=urlHash;
mem=new HashMap();
mem.put(BOOKMARK_URL, url);
tags=new HashSet();
timestamp=System.currentTimeMillis();
}
public Map getMap(){
mem.put(BOOKMARK_TAGS, listManager.hashset2string(tags));
mem.put(BOOKMARK_TIMESTAMP, String.valueOf(this.timestamp));
return mem;
}
private void loadTimestamp(){
if(this.mem.containsKey(BOOKMARK_TIMESTAMP))
this.timestamp=Long.parseLong((String)mem.get(BOOKMARK_TIMESTAMP));
}
public String getUrlHash(){
return urlHash;
}
public String getUrl(){
return (String) this.mem.get(BOOKMARK_URL);
}
public String getTags(){
if(this.mem.containsKey(BOOKMARK_TAGS)){
return (String)this.mem.get(BOOKMARK_TAGS);
}
return "";
public HashSet getTags(){
return tags;
}
public ArrayList getTagsList(){
return listManager.string2arraylist(this.getTags());
public String getTagsString(){
return listManager.hashset2string(getTags());
}
public String getDescription(){
if(this.mem.containsKey(BOOKMARK_DESCRIPTION)){
@ -809,14 +824,7 @@ public class bookmarksDB {
//setBookmarksTable();
}
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);
this.setTags(tags, true);
}
/**
* 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
*/
public void setTags(HashSet tags, boolean local){
mem.put(BOOKMARK_TAGS, listManager.hashset2string(tags));
tags.addAll(tags);
Iterator it=tags.iterator();
while(it.hasNext()){
String tagName=(String) it.next();
@ -839,7 +847,7 @@ public class bookmarksDB {
if(tag == null){
tag=new Tag(tagName);
}
tag.add(getUrlHash());
tag.addUrl(getUrlHash());
if(local){
saveTag(tag);
}
@ -847,14 +855,10 @@ public class bookmarksDB {
}
public long getTimeStamp(){
if(mem.containsKey(BOOKMARK_TIMESTAMP)){
return Long.parseLong((String)mem.get(BOOKMARK_TIMESTAMP));
}else{
return 0;
}
return timestamp;
}
public void setTimeStamp(long timestamp){
this.mem.put(BOOKMARK_TIMESTAMP, String.valueOf(timestamp));
public void setTimeStamp(long ts){
this.timestamp=ts;
}
}
public class tagIterator implements Iterator{
@ -943,10 +947,21 @@ public class bookmarksDB {
Bookmark bm1=getBookmark((String)obj1);
Bookmark bm2=getBookmark((String)obj2);
//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();
}else{
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