3 package LJ
::ExpungedUsers
;
12 my $within = delete $opts{within
} || 3600;
13 my $limit = delete $opts{limit
} || 100;
15 croak
"invalid arguments: " . join(",", keys %opts)
18 my $dbr = LJ
::get_db_reader
()
19 or die "unable to contact global reader";
21 my $sth = $dbr->prepare
22 ("SELECT userid, expunge_time FROM expunged_users " .
23 "WHERE expunge_time > UNIX_TIMESTAMP() - ? LIMIT $limit");
24 $sth->execute($within);
27 my %exp_times = (); # uid => exp_time
28 while (my ($uid, $exp_time) = $sth->fetchrow_array) {
30 $exp_times{$uid} = $exp_time;
33 my $us = LJ
::load_userids
(@uids);
35 return (grep { $_->[0]->{user
} !~ /^ex_/ && !$_->[0]->is_identity }
36 sort { $a->[0]->{user
} cmp $b->[0]->{user
} }
37 map { [ $us->{$_}, $exp_times{$_} ] } @uids);
40 sub load_single_user
{
44 $user = LJ
::canonical_username
($user);
45 croak
"invalid user: $user"
48 my $u = LJ
::load_user
($user);
50 # is the user actually expunged?
51 return unless $u && $u->is_expunged;
53 # did someone rename to it?
54 return if $u->user =~ /^ex_/;
64 $user = LJ
::canonical_username
($user);
65 croak
"invalid user: $user"
68 return $class->_query_result_array
69 ("SELECT userid, expunge_time FROM expunged_users " .
70 "WHERE user LIKE ? LIMIT 10", $user . "%");
73 sub _query_result_array
{
75 my ($sql, @vals) = @_;
77 my $dbr = LJ
::get_db_reader
()
78 or die "unable to contact global reader";
80 my $sth = $dbr->prepare($sql);
82 die $dbr->errstr if $dbr->err;
85 while (my ($uid, $exp_time) = $sth->fetchrow_array) {
86 push @rows, [ $uid => $exp_time ];
89 my $us = LJ
::load_userids
(map { $_->[0] } @rows);
91 foreach my $row (@rows) {
92 my $u = $us->{$row->[0]};
94 # someone already renamed to this?
95 next if $u->{user
} =~ /^ex_/;
97 # push all users except for identity users
98 push @ret, [ $u => $row->[1] ] unless $u->is_identity;
104 sub random_by_letter
{
108 my $letter = substr(delete $opts{letter
}, 0, 1) || '0';
109 my $prev_max = delete $opts{prev_max
} || 0;
110 my $limit = delete $opts{limit
} || 100;
112 croak
"invalid arguments: " . join(",", keys %opts)
115 my $dbr = LJ
::get_db_reader
()
116 or die "unable to contact global reader";
118 my $min = $prev_max + 0;
120 my $sth = $dbr->prepare
121 ("SELECT userid, expunge_time FROM expunged_users " .
122 "WHERE (user LIKE ? OR user LIKE ?) AND expunge_time>? " .
124 $sth->execute(uc($letter) . '%', lc($letter) . '%', $min);
125 die $dbr->errstr if $dbr->err;
128 while (my ($uid, $exp_time) = $sth->fetchrow_array) {
129 push @rows, [ $uid => $exp_time ];
132 # if we got less than the limit, then we hit the beginning
133 if (@rows < $limit) {
134 my $new_limit = $limit - @rows;
136 ("SELECT userid, expunge_time FROM expunged_users " .
137 "WHERE (user LIKE ? OR user LIKE ?) AND expunge_time>? " .
139 $sth->execute(uc($letter) . '%', lc($letter). '%', 0);
140 die $dbr->errstr if $dbr->err;
142 while (my ($uid, $exp_time) = $sth->fetchrow_array) {
143 push @rows, [ $uid => $exp_time ];
147 my $us = LJ
::load_userids
(map { $_->[0] } @rows);
149 foreach my $row (@rows) {
150 my $u = $us->{$row->[0]};
152 # someone already renamed to this?
153 next if $u->{user
} =~ /^ex_/;
155 # push all users except for identity users
156 push @ret, [ $u => $row->[1] ] unless $u->is_identity;