shlist

share and manage lists between multiple people
Log | Files | Refs

commit 2f685d0dbb321a3def8cd1489bb8db2d072adbb3
parent a7a570d95d4f221e3927a8c9e9873714461df6f9
Author: kyle <kyle@0x30.net>
Date:   Sat, 23 Jan 2016 00:34:40 -0700

sl: simplify lists_get_other a bit

- use an sql query of the form:
  "select all lists my friend is in except for lists i'm in"
- this lets us get rid of code that was filtering lists we were already in that
  were obtained from the friends list query

Diffstat:
Mserver/sl | 21+++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/server/sl b/server/sl @@ -511,13 +511,6 @@ sub msg_lists_get_other { $log->print("gathering lists for '$dev->{fp}'\n"); - # Get lists this device is already in, used for filtering later - my @my_lists; - $db->{get_lists}->execute($dev->{num}); - while (my ($list_num) = $db->{get_lists}->fetchrow_array()) { - push @my_lists, $list_num; - } - my %list_nums; # Find all mutual friends of this device $db->{mutual_friend_select}->execute($dev->{num}); @@ -528,11 +521,8 @@ sub msg_lists_get_other { $log->print("found mutual friend '$friend_phnum'\n"); # Find all of the lists my mutual friend is in (but not me) - $db->{get_lists}->execute($friend_num); - while (my ($list_num, $name) = $db->{get_lists}->fetchrow_array()) { - - # Filter out lists my device is already in - next if (grep {$_ eq $list_num} @my_lists); + $db->{get_other_lists}->execute($friend_num, $dev->{num}); + while (my ($list_num) = $db->{get_other_lists}->fetchrow_array()) { if (exists $list_nums{$list_num}) { # Append member and move on @@ -541,6 +531,9 @@ sub msg_lists_get_other { next } + $db->{list_select}->execute($list_num); + my (undef, $name) = $db->{list_select}->fetchrow_array(); + my $list = { num => $list_num, name => $name, @@ -847,6 +840,10 @@ sub prepare_stmt_handles { $sql = 'select device from list_members where list = ? and device = ?'; $self->{check_list_member} = $dbh->prepare($sql); + $sql = qq{select list from list_members where device = ? except + select list from list_members where device = ?}; + $self->{get_other_lists} = $dbh->prepare($sql); + # list_data table queries $sql = 'delete from list_data where list = ?'; $self->{delete_list_data} = $dbh->prepare($sql);