Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache fixes #8616

Merged
merged 1 commit into from Feb 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
86 changes: 61 additions & 25 deletions src/com/dotmarketing/tag/business/TagAPIImpl.java
Expand Up @@ -584,22 +584,40 @@ public TagInode addUserTagInode(Tag tag, String inode) throws DotDataException {
*/
public TagInode addContentletTagInode(Tag tag, String inode, String fieldVarName) throws DotDataException {

//validates the tagInode already exists
TagInode existingTagInode = getTagInode(tag.getTagId(), inode, fieldVarName);
boolean localTransaction = false;

try {

//Check for a transaction and start one if required
localTransaction = HibernateUtil.startLocalTransactionIfNeeded();

//validates the tagInode already exists
TagInode existingTagInode = getTagInode(tag.getTagId(), inode, fieldVarName);

if ( existingTagInode == null || existingTagInode.getTagId() == null ) {

if ( existingTagInode == null || existingTagInode.getTagId() == null ) {
//the tagInode does not exists, so create a new TagInode
TagInode tagInode = new TagInode();
tagInode.setTagId(tag.getTagId());
tagInode.setInode(inode);
tagInode.setFieldVarName(fieldVarName);
tagInode.setModDate(new Date());

existingTagInode = tagFactory.createTagInode(tagInode);
}

//the tagInode does not exists, so creates a new TagInode
TagInode tagInode = new TagInode();
tagInode.setTagId(tag.getTagId());
tagInode.setInode(inode);
tagInode.setFieldVarName(fieldVarName);
tagInode.setModDate(new Date());
//Everything ok..., committing the transaction
if ( localTransaction ) {
HibernateUtil.commitTransaction();
}

return tagFactory.createTagInode(tagInode);
} else {
// returning the existing tagInode
return existingTagInode;

} catch (Exception e) {
if ( localTransaction ) {
HibernateUtil.rollbackTransaction();
}
throw e;
}
}

Expand Down Expand Up @@ -920,22 +938,40 @@ public List<Tag> getTagsInText ( String text, String hostId ) throws DotSecurity
@Override
public List<Tag> getTagsInText ( String text, String userId, String hostId ) throws DotSecurityException, DotDataException {

List<Tag> tags = new ArrayList<>();
boolean localTransaction = false;

//Split the given list of tasks
String[] tagNames = text.split("[,\\n\\t\\r]");
for ( String tagname : tagNames ) {
tagname = tagname.trim();
if ( tagname.length() > 0 ) {
/*
Search for this given tag and create it if does not exist, the search in order to define
if the tag exist will include the system host
*/
tags.add(getTagAndCreate(tagname, userId, hostId, false, true));
try {

//Check for a transaction and start one if required
localTransaction = HibernateUtil.startLocalTransactionIfNeeded();

List<Tag> tags = new ArrayList<>();

//Split the given list of tasks
String[] tagNames = text.split("[,\\n\\t\\r]");
for ( String tagname : tagNames ) {
tagname = tagname.trim();
if ( tagname.length() > 0 ) {
/*
Search for this given tag and create it if does not exist, the search in order to define
if the tag exist will include the system host
*/
tags.add(getTagAndCreate(tagname, userId, hostId, false, true));
}
}
}

return tags;
//Everything ok..., committing the transaction
if ( localTransaction ) {
HibernateUtil.commitTransaction();
}

return tags;
} catch (Exception e) {
if ( localTransaction ) {
HibernateUtil.rollbackTransaction();
}
throw e;
}
}

}
7 changes: 7 additions & 0 deletions src/com/dotmarketing/tag/business/TagCacheImpl.java
Expand Up @@ -103,6 +103,13 @@ protected void putForHost ( String hostId, List<Tag> tags ) {

@Override
protected void put ( Tag object ) {

//First clean up list references to this tag name and host
//Removing by name
cache.remove(getTagsByNameGroup() + object.getTagName().toLowerCase(), getTagsByNameGroup());
//Removing by host
cache.remove(getTagsByHostGroup() + object.getHostId(), getTagsByHostGroup());

//Adding the tag by id
cache.put(getPrimaryGroup() + object.getTagId(), object, getPrimaryGroup());
cache.put(getTagByNameHostGroup() + object.getTagName().toLowerCase() + "_" + object.getHostId(), object, getTagByNameHostGroup());
Expand Down
6 changes: 6 additions & 0 deletions src/com/dotmarketing/tag/business/TagFactoryImpl.java
Expand Up @@ -423,6 +423,9 @@ public Tag createTag(Tag tag) throws DotDataException {

dc.loadResult();

//Clean up list references to this tag name and host
tagCache.remove(tag);

return tag;
}

Expand All @@ -448,6 +451,9 @@ public TagInode createTagInode ( TagInode tagInode ) throws DotDataException {

dc.loadResult();

//Clean up list references to this inode
tagInodeCache.remove(tagInode);

return tagInode;
}

Expand Down
4 changes: 4 additions & 0 deletions src/com/dotmarketing/tag/business/TagInodeCacheImpl.java
Expand Up @@ -51,6 +51,10 @@ protected void put ( TagInode object ) {
fieldVarName = object.getFieldVarName();
}

//First clean up list references to this inode and tag id
cache.remove(getTagInodesByInodeGroup() + object.getInode(), getTagInodesByInodeGroup());
cache.remove(getTagInodesByTagIdGroup() + object.getTagId(), getTagInodesByTagIdGroup());

//Adding the tag inode using the ids
cache.put(getPrimaryGroup() + object.getTagId() + "_" + object.getInode() + "_" + fieldVarName, object, getPrimaryGroup());
}
Expand Down