diff options
| author | Teddy Wing | 2016-09-17 18:11:33 -0400 |
|---|---|---|
| committer | Teddy Wing | 2016-09-17 18:11:33 -0400 |
| commit | 5290854d1dfa9c6750c153574b6dcca40e41121e (patch) | |
| tree | 8ffa31429640f1819e534987cba8dd90c705a5c0 | |
| parent | cabbb06d4f9b4d6a527698e17481402c2084a66c (diff) | |
| download | irssi-slack-profile-5290854d1dfa9c6750c153574b6dcca40e41121e.tar.bz2 | |
find_user: Only request custom fields & presence if not already there
Previously we would make API requests for user profile information and
presence information every time we invoked `find_user($nick)`.
Since we store all users in memory in `@users_list`, once that data is
requested the first time, it's saved for future use.
If the data is already there locally in memory, there's no point in
wasting time and network to request the data again. So only make the API
requests if we don't already have the data.
| -rw-r--r-- | slack_profile.pl | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/slack_profile.pl b/slack_profile.pl index 5d3a60b..6cfe0d7 100644 --- a/slack_profile.pl +++ b/slack_profile.pl @@ -246,11 +246,15 @@ sub find_user { for my $user (@users_list) { if ($user->{'name'} eq $username) { - my $profile = fetch_user_profile($user); - $user->{'fields'} = $profile->{'fields'}; + unless (exists $user->{'fields'}) { + my $profile = fetch_user_profile($user); + $user->{'fields'} = $profile->{'fields'}; + } - my $presence = fetch_user_presence($user); - $user->{'presence'} = $presence; + unless (exists $user->{'presence'}) { + my $presence = fetch_user_presence($user); + $user->{'presence'} = $presence; + } return $user; } |
