[longomatch] filter: improve filter perf caching filtering results
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] filter: improve filter perf caching filtering results
- Date: Sat, 20 Apr 2013 17:33:09 +0000 (UTC)
commit 0163a58a0821292db567b680142c18ae5333c38c
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Sat Apr 20 19:21:25 2013 +0200
filter: improve filter perf caching filtering results
LongoMatch.Core/Common/PlaysFilter.cs | 66 +++++++++++++++++++++++++++++------
1 file changed, 56 insertions(+), 10 deletions(-)
---
diff --git a/LongoMatch.Core/Common/PlaysFilter.cs b/LongoMatch.Core/Common/PlaysFilter.cs
index fc3904f..535c73e 100644
--- a/LongoMatch.Core/Common/PlaysFilter.cs
+++ b/LongoMatch.Core/Common/PlaysFilter.cs
@@ -35,6 +35,9 @@ namespace LongoMatch.Common
Dictionary<Category, List<SubCategoryTags>> categoriesFilter;
List<Player> playersFilter;
Project project;
+ List<Category> visibleCategories;
+ List<Play> visiblePlays;
+ List<Player> visiblePlayers;
public PlaysFilter (Project project)
{
@@ -42,6 +45,7 @@ namespace LongoMatch.Common
categoriesFilter = new Dictionary<Category, List<SubCategoryTags>>();
playersFilter = new List<Player>();
ClearAll();
+ UpdateFilters();
}
public bool PlayersFilterEnabled {
@@ -65,6 +69,7 @@ namespace LongoMatch.Common
}
public void Update () {
+ UpdateFilters();
EmitFilterUpdated();
}
@@ -117,26 +122,66 @@ namespace LongoMatch.Common
public List<Category> VisibleCategories {
get {
- return categoriesFilter.Keys.ToList();
+ return visibleCategories;
}
}
public List<Player> VisiblePlayers {
get {
- return playersFilter;
+ return visiblePlayers;
}
}
public bool IsVisible(object o) {
if (o is Player) {
- if (PlayersFilterEnabled)
- return VisiblePlayers.Contains(o as Player);
- else
- return true;
+ return visiblePlayers.Contains(o as Player);
} else if (o is Play) {
- bool cat_match=true, player_match=true;
- Play play = o as Play;
+ return visiblePlays.Contains (o as Play);
+ }
+ return true;
+ }
+
+ void UpdateFilters () {
+ UpdateVisibleCategories ();
+ UpdateVisiblePlays ();
+ UpdateVisiblePlayers ();
+ }
+
+ void UpdateVisiblePlayers () {
+ visiblePlayers = new List<Player>();
+ if (PlayersFilterEnabled) {
+ return;
+ }
+
+ foreach (Player p in project.LocalTeamTemplate.Concat (project.VisitorTeamTemplate)) {
+ if (playersFilter.Contains (p)) {
+ visiblePlayers.Add (p);
+ }
+ }
+ }
+
+ void UpdateVisibleCategories () {
+ visibleCategories = new List<Category>();
+ foreach (var c in categoriesFilter.Keys) {
+ bool visible = false;
+ if (!CategoriesFilterEnabled) {
+ visible = true;
+ } else {
+ foreach (var subcat in categoriesFilter[c]) {
+ if (subcat.Count != 0)
+ visible = true;
+ }
+ }
+ if (visible)
+ visibleCategories.Add (c);
+ }
+ }
+
+ void UpdateVisiblePlays () {
+ bool cat_match=true, player_match=true;
+ visiblePlays = new List<Play>();
+ foreach (Play play in project.AllPlays()) {
if (CategoriesFilterEnabled) {
cat_match = false;
foreach (var subcat in categoriesFilter[play.Category]) {
@@ -163,9 +208,10 @@ namespace LongoMatch.Common
if (PlayersFilterEnabled)
player_match =
VisiblePlayers.Intersect(play.Players.GetTagsValues()).Count() != 0;
- return player_match && cat_match;
+ if (player_match && cat_match) {
+ visiblePlays.Add (play);
+ }
}
- return true;
}
void EmitFilterUpdated () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]