mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 15:37:56 +01:00
Improve purge.
This commit is contained in:
parent
dcd59efc12
commit
3137f78cce
@ -67,5 +67,5 @@ public interface MindmapManager {
|
||||
|
||||
void updateCollaboration(@NotNull Collaboration collaboration);
|
||||
|
||||
void removeHistory(int mapId);
|
||||
void purgeHistory(int mapId);
|
||||
}
|
||||
|
@ -73,23 +73,25 @@ public class MindmapManagerImpl
|
||||
getHibernateTemplate().save(collaboration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge history map ....
|
||||
* @param mapId
|
||||
*/
|
||||
@Override
|
||||
public void removeHistory(int mapId) {
|
||||
public void purgeHistory(int mapId) {
|
||||
final Criteria hibernateCriteria = getSession().createCriteria(MindMapHistory.class);
|
||||
hibernateCriteria.add(Restrictions.eq("mindmapId", mapId));
|
||||
hibernateCriteria.addOrder(Order.desc("creationTime"));
|
||||
|
||||
final List<MindMapHistory> historyList = hibernateCriteria.list();
|
||||
int i = 0;
|
||||
for (MindMapHistory history : historyList) {
|
||||
if (i > 20) {
|
||||
getHibernateTemplate().delete(history);
|
||||
|
||||
final Mindmap mindmapById = this.getMindmapById(mapId);
|
||||
final Calendar yearAgo = Calendar.getInstance();
|
||||
yearAgo.add(Calendar.MONTH, -12);
|
||||
|
||||
// If the map has not been modified in the last months, it means that I don't need to keep all the history ...
|
||||
int max = mindmapById.getLastModificationTime().before(yearAgo) ? 10 : 25;
|
||||
|
||||
if (historyList.size() > max) {
|
||||
for (int i = max; i < historyList.size(); i++) {
|
||||
getHibernateTemplate().delete(historyList.get(i));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,6 @@ import com.wisemapping.service.UserService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -167,7 +166,7 @@ public class AdminController extends BaseController {
|
||||
}
|
||||
|
||||
// Purge history ...
|
||||
mindmapService.removeHistory(mindmap.getId());
|
||||
mindmapService.purgeHistory(mindmap.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -185,7 +184,7 @@ public class AdminController extends BaseController {
|
||||
@RequestMapping(method = RequestMethod.GET, value = "admin/database/purge/history")
|
||||
public void purgeHistory(@RequestParam(required = true) Integer mapId) throws WiseMappingException, UnsupportedEncodingException {
|
||||
|
||||
mindmapService.removeHistory(mapId);
|
||||
mindmapService.purgeHistory(mapId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -68,5 +68,5 @@ public interface MindmapService {
|
||||
|
||||
boolean isAdmin(@Nullable User user);
|
||||
|
||||
void removeHistory(int mapId);
|
||||
void purgeHistory(int mapId);
|
||||
}
|
||||
|
@ -83,8 +83,8 @@ public class MindmapServiceImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHistory(int mapId) {
|
||||
mindmapManager.removeHistory(mapId);
|
||||
public void purgeHistory(int mapId) {
|
||||
mindmapManager.purgeHistory(mapId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,6 +30,7 @@
|
||||
<value>update*</value>
|
||||
<value>add*</value>
|
||||
<value>remove*</value>
|
||||
<value>purge*</value>
|
||||
<value>revert*</value>
|
||||
</list>
|
||||
</property>
|
||||
|
@ -53,7 +53,7 @@
|
||||
<property name="dataSource" ref="wiseDataSource"/>
|
||||
</bean>
|
||||
|
||||
<!-- Hibernate Template Defintion -->
|
||||
<!-- Hibernate Template Definition -->
|
||||
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
|
||||
<property name="sessionFactory" ref="mindmapSessionFactory"/>
|
||||
<property name="jdbcExceptionTranslator" ref="jdbcExceptionTranslator"/>
|
||||
|
Loading…
Reference in New Issue
Block a user