+% my $curuser = $FS::CurrentUser::CurrentUser;
+% my $numcust = $curuser->option('dashboard_customers');
+% $numcust ||= 10 unless $numcust =~ /^\s*0+\s*$/;
+% if ( $numcust ) {
+%
+% warn time.": fetching recently changed customers\n" if $debug;
+%
+% my $sth = dbh->prepare(
+% #"SELECT DISTINCT custnum FROM h_cust_main JOIN cust_main USING ( custnum )
+% "SELECT custnum FROM h_cust_main JOIN cust_main USING ( custnum )
+% WHERE ( history_action = 'insert' OR history_action = 'replace_new' )
+% AND ( history_usernum = ? OR history_user = ? )
+% AND ". $curuser->agentnums_sql( table=>'cust_main' ).
+% " ORDER BY history_date desc LIMIT 1000" # LIMIT 10
+% ) or die dbh->errstr;
+%
+%
+% $sth->execute( $curuser->usernum, $curuser->username ) or die $sth->errstr;
+%
+% my %saw = ();
+% my @custnums = grep { !$saw{$_}++ } map $_->[0], @{ $sth->fetchall_arrayref };
+%
+% @custnums = splice(@custnums, 0, $numcust);
+%
+% if ( @custnums ) {
+% warn time.": displaying recently changed customers\n" if $debug;