Skip to content
Snippets Groups Projects
Commit f8f73669 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

improved report tab performance (tags are now cached locally) (#243)

parent 7848d135
Branches
Tags
No related merge requests found
package de.deadlocker8.budgetmaster.logic.tag;
import java.util.ArrayList;
import java.util.HashMap;
import de.deadlocker8.budgetmaster.logic.payment.Payment;
import de.deadlocker8.budgetmaster.logic.payment.RepeatingPaymentEntry;
public class TagCache
{
private HashMap<Integer, ArrayList<Tag>> normalPaymentTagCache;
private HashMap<Integer, ArrayList<Tag>> repeatingPaymentTagCache;
public TagCache()
{
clear();
}
public void clear()
{
normalPaymentTagCache = new HashMap<>();
repeatingPaymentTagCache = new HashMap<>();
}
public void addTags(Payment payment, ArrayList<Tag> tags)
{
if(payment instanceof RepeatingPaymentEntry)
{
repeatingPaymentTagCache.put(((RepeatingPaymentEntry)payment).getRepeatingPaymentID(), tags);
}
else
{
normalPaymentTagCache.put(payment.getID(), tags);
}
}
public ArrayList<Tag> getTags(Payment payment)
{
if(payment instanceof RepeatingPaymentEntry)
{
RepeatingPaymentEntry repeatingPayment = (RepeatingPaymentEntry)payment;
if(repeatingPaymentTagCache.containsKey(repeatingPayment.getRepeatingPaymentID()))
{
return repeatingPaymentTagCache.get(repeatingPayment.getRepeatingPaymentID());
}
}
else
{
if(normalPaymentTagCache.containsKey(payment.getID()))
{
return normalPaymentTagCache.get(payment.getID());
}
}
return null;
}
public HashMap<Integer, ArrayList<Tag>> getNormalPaymentTagCache()
{
return normalPaymentTagCache;
}
public HashMap<Integer, ArrayList<Tag>> getRepeatingPaymentTagCache()
{
return repeatingPaymentTagCache;
}
}
\ No newline at end of file
...@@ -11,15 +11,22 @@ import de.deadlocker8.budgetmaster.logic.serverconnection.ServerTagConnection; ...@@ -11,15 +11,22 @@ import de.deadlocker8.budgetmaster.logic.serverconnection.ServerTagConnection;
public class TagHandler public class TagHandler
{ {
private Settings settings; private Settings settings;
private TagCache tagCache;
public TagHandler(Settings settings) public TagHandler(Settings settings)
{ {
this.settings = settings; this.settings = settings;
this.tagCache = new TagCache();
} }
public ArrayList<Tag> getTags(Payment payment) throws Exception public ArrayList<Tag> getTags(Payment payment) throws Exception
{ {
ArrayList<Tag> tags = new ArrayList<>(); ArrayList<Tag> tags = new ArrayList<>();
ArrayList<Tag> cachedTags = tagCache.getTags(payment);
if(cachedTags != null)
{
return cachedTags;
}
ServerTagConnection connection = new ServerTagConnection(settings); ServerTagConnection connection = new ServerTagConnection(settings);
...@@ -32,6 +39,8 @@ public class TagHandler ...@@ -32,6 +39,8 @@ public class TagHandler
tags.addAll(connection.getAllTagsForRepeatingPayment(((RepeatingPaymentEntry)payment).getRepeatingPaymentID())); tags.addAll(connection.getAllTagsForRepeatingPayment(((RepeatingPaymentEntry)payment).getRepeatingPaymentID()));
} }
tagCache.addTags(payment, tags);
return tags; return tags;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment