summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2007-05-01 19:57:40 +0000
committerivan <ivan>2007-05-01 19:57:40 +0000
commit86330b16240feb45baeaa5aa466b2b42c8a3e7fe (patch)
tree605d0f4345f725d0a5455a7964320a5d813d13c0 /FS
parent7cdcb8d249f66efdbd5eb4efdd6e07f0f7948b49 (diff)
use FS::ClientAPI_SessionCache for signup info so it actually works - speed up signups
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/ClientAPI/Signup.pm136
-rw-r--r--FS/bin/freeside-selfservice-server8
2 files changed, 106 insertions, 38 deletions
diff --git a/FS/FS/ClientAPI/Signup.pm b/FS/FS/ClientAPI/Signup.pm
index 6dded4ccf..39485b06d 100644
--- a/FS/FS/ClientAPI/Signup.pm
+++ b/FS/FS/ClientAPI/Signup.pm
@@ -1,6 +1,8 @@
package FS::ClientAPI::Signup;
use strict;
+use vars qw($DEBUG $me);
+use Data::Dumper;
use Tie::RefHash;
use FS::Conf;
use FS::Record qw(qsearch qsearchs dbdef);
@@ -18,29 +20,30 @@ use FS::acct_snarf;
use FS::queue;
use FS::reg_code;
+$DEBUG = 2;
+$me = '[FS::ClientAPI::Signup]';
+
sub signup_info {
my $packet = shift;
+ warn "$me signup_info called on $packet\n" if $DEBUG;
+
my $conf = new FS::Conf;
- use vars qw($signup_info_cache); #cache for performance;
- $signup_info_cache ||= {
- 'cust_main_county' =>
- [ map { $_->hashref } qsearch('cust_main_county', {}) ],
+ my $cache = new FS::ClientAPI_SessionCache( {
+ 'namespace' => 'FS::ClientAPI::Signup',
+ } );
+ my $signup_info_cache = $cache->get('signup_info_cache');
- 'agent' =>
- [
- map { $_->hashref }
- qsearch('agent', { 'disabled' => '' } )
- ],
+ if ( $signup_info_cache ) {
- 'part_referral' =>
- [
- map { $_->hashref }
- qsearch('part_referral', { 'disabled' => '' })
- ],
+ warn "$me loading cached signup info\n" if $DEBUG > 1;
+
+ } else {
+
+ warn "$me populating signup info cache\n" if $DEBUG > 1;
- 'agentnum2part_pkg' =>
+ my $agentnum2part_pkg =
{
map {
my $href = $_->pkgpart_hashref;
@@ -55,47 +58,75 @@ sub signup_info {
qsearch( 'part_pkg', { 'disabled' => '' } )
];
} qsearch('agent', { 'disabled' => '' })
- },
+ };
+
+ my $msgcat = { map { $_=>gettext($_) }
+ qw( passwords_dont_match invalid_card unknown_card_type
+ not_a empty_password illegal_or_empty_text )
+ };
+ warn "msgcat: ". Dumper($msgcat). "\n" if $DEBUG > 2;
+
+ my $label = { map { $_ => FS::Msgcat::_gettext($_) }
+ qw( stateid stateid_state )
+ };
+ warn "label: ". Dumper($label). "\n" if $DEBUG > 2;
+
+ $signup_info_cache = {
+ 'cust_main_county' => [ map $_->hashref,
+ qsearch('cust_main_county', {} )
+ ],
+
+ 'agent' => [ map $_->hashref,
+ qsearch('agent', { 'disabled' => '' } )
+ ],
+
+ 'part_referral' => [ map $_->hashref,
+ qsearch('part_referral', { 'disabled' => '' } )
+ ],
+
+ 'agentnum2part_pkg' => $agentnum2part_pkg,
- 'svc_acct_pop' => [ map { $_->hashref } qsearch('svc_acct_pop',{} ) ],
+ 'svc_acct_pop' => [ map $_->hashref, qsearch('svc_acct_pop',{} ) ],
- 'emailinvoiceonly' => $conf->exists('emailinvoiceonly'),
+ 'emailinvoiceonly' => $conf->exists('emailinvoiceonly'),
- 'security_phrase' => $conf->exists('security_phrase'),
+ 'security_phrase' => $conf->exists('security_phrase'),
- 'payby' => [ $conf->config('signup_server-payby') ],
+ 'payby' => [ $conf->config('signup_server-payby') ],
- 'card_types' => card_types(),
+ 'card_types' => card_types(),
- 'paytypes' => [ @FS::cust_main::paytypes ],
+ 'paytypes' => [ @FS::cust_main::paytypes ],
- 'cvv_enabled' => defined dbdef->table('cust_main')->column('paycvv'), # 1,
+ 'cvv_enabled' => 1,
- 'stateid_enabled' => $conf->exists('show_stateid'),
+ 'stateid_enabled' => $conf->exists('show_stateid'),
- 'paystate_enabled' => $conf->exists('show_bankstate'),
+ 'paystate_enabled' => $conf->exists('show_bankstate'),
- 'ship_enabled' => defined dbdef->table('cust_main')->column('ship_last'),#1,
+ 'ship_enabled' => 1,
- 'msgcat' => { map { $_=>gettext($_) } qw(
- passwords_dont_match invalid_card unknown_card_type not_a empty_password illegal_or_empty_text
- ) },
+ 'msgcat' => $msgcat,
- 'label' => { map { $_ => FS::Msgcat::_gettext($_) } qw(
- stateid stateid_state
- ) },
+ 'label' => $label,
- 'statedefault' => $conf->config('statedefault') || 'CA',
+ 'statedefault' => scalar($conf->config('statedefault')) || 'CA',
- 'countrydefault' => $conf->config('countrydefault') || 'US',
+ 'countrydefault' => scalar($conf->config('countrydefault')) || 'US',
- 'refnum' => $conf->config('signup_server-default_refnum'),
+ 'refnum' => scalar($conf->config('signup_server-default_refnum')),
- 'default_pkgpart' => $conf->config('signup_server-default_pkgpart'),
+ 'default_pkgpart' => scalar($conf->config('signup_server-default_pkgpart')),
- };
+ };
+
+ $cache->set('signup_info_cache', $signup_info_cache);
+
+ }
my $signup_info = { %$signup_info_cache };
+ warn "$me signup info loaded\n" if $DEBUG > 1;
+ warn Dumper($signup_info). "\n" if $DEBUG > 2;
my @addl = qw( signup_server-classnum2 signup_server-classnum3 );
@@ -104,6 +135,9 @@ sub signup_info {
$signup_info->{optional_packages} = [];
foreach my $addl ( @addl ) {
+
+ warn "$me adding optional package info\n" if $DEBUG > 1;
+
my $classnum = $conf->config($addl) or next;
my @pkgs = map { {
@@ -116,6 +150,8 @@ sub signup_info {
push @{$signup_info->{optional_packages}}, \@pkgs;
+ warn "$me done adding opt. package info for $classnum\n" if $DEBUG > 1;
+
}
}
@@ -127,6 +163,8 @@ sub signup_info {
my $session = '';
if ( exists $packet->{'session_id'} ) {
+
+ warn "$me loading agent session\n" if $DEBUG > 1;
my $cache = new FS::ClientAPI_SessionCache( {
'namespace' => 'FS::ClientAPI::Agent',
} );
@@ -136,7 +174,11 @@ sub signup_info {
} else {
return { 'error' => "Can't resume session" }; #better error message
}
- }elsif( exists $packet->{'customer_session_id'} ) {
+ warn "$me done loading agent session\n" if $DEBUG > 1;
+
+ } elsif ( exists $packet->{'customer_session_id'} ) {
+
+ warn "$me loading customer session\n" if $DEBUG > 1;
my $cache = new FS::ClientAPI_SessionCache( {
'namespace' => 'FS::ClientAPI::MyAccount',
} );
@@ -149,11 +191,16 @@ sub signup_info {
} else {
return { 'error' => "Can't resume session" }; #better error message
}
+ warn "$me done loading customer session\n" if $DEBUG > 1;
+
}
$signup_info->{'part_pkg'} = [];
if ( $packet->{'reg_code'} ) {
+
+ warn "$me setting package list via reg_code\n" if $DEBUG > 1;
+
$signup_info->{'part_pkg'} =
[ map { { 'payby' => [ $_->payby ],
'freq_pretty' => $_->freq_pretty,
@@ -171,8 +218,12 @@ sub signup_info {
$signup_info->{'error'} = 'Unknown registration code'
unless @{ $signup_info->{'part_pkg'} };
+ warn "$me done setting package list via reg_code\n" if $DEBUG > 1;
+
} elsif ( $packet->{'promo_code'} ) {
+ warn "$me setting package list via promo_code\n" if $DEBUG > 1;
+
$signup_info->{'part_pkg'} =
[ map { { 'payby' => [ $_->payby ],
'freq_pretty' => $_->freq_pretty,
@@ -189,12 +240,18 @@ sub signup_info {
$signup_info->{'error'} = 'Unknown promotional code'
unless @{ $signup_info->{'part_pkg'} };
+
+ warn "$me done setting package list via promo_code\n" if $DEBUG > 1;
}
if ( $agentnum ) {
+
+ warn "$me setting agent-specific package list\n" if $DEBUG > 1;
$signup_info->{'part_pkg'} = $signup_info->{'agentnum2part_pkg'}{$agentnum}
unless @{ $signup_info->{'part_pkg'} };
+ warn "$me done setting agent-specific package list\n" if $DEBUG > 1;
+ warn "$me setting agent-specific adv. source list\n" if $DEBUG > 1;
$signup_info->{'part_referral'} =
[
map { $_->hashref }
@@ -206,15 +263,18 @@ sub signup_info {
},
)
];
+ warn "$me done setting agent-specific adv. source list\n" if $DEBUG > 1;
}
# else {
# delete $signup_info->{'part_pkg'};
#}
+ warn "$me sorting package list\n" if $DEBUG > 1;
$signup_info->{'part_pkg'} = [ sort { $a->{pkg} cmp $b->{pkg} } # case?
@{ $signup_info->{'part_pkg'} }
];
+ warn "$me done sorting package list\n" if $DEBUG > 1;
if ( exists $packet->{'session_id'} ) {
my $agent_signup_info = { %$signup_info };
diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server
index 205f1c3ab..2087e7130 100644
--- a/FS/bin/freeside-selfservice-server
+++ b/FS/bin/freeside-selfservice-server
@@ -14,6 +14,7 @@ use Net::SSH qw(sshopen2);
use FS::Daemon qw(daemonize1 drop_root logfile daemonize2 sigint sigterm);
use FS::UID qw(adminsuidsetup forksuidsetup);
use FS::ClientAPI;
+use FS::ClientAPI_SessionCache;
use FS::Conf;
use FS::cust_svc;
@@ -62,6 +63,13 @@ if ( $conf->exists('selfservice-ignore_quantity') ) {
$FS::cust_svc::ignore_quantity = 1; #now it is used twice.
}
+#clear the signup info cache so an "/etc/init.d/freeside restart" will pick
+#up new info... (better as a callback in Signup.pm?)
+my $cache = new FS::ClientAPI_SessionCache( {
+ 'namespace' => 'FS::ClientAPI::Signup',
+} );
+$cache->remove('signup_info_cache');
+
my $clientd = "/usr/local/sbin/freeside-selfservice-clientd"; #better name?
my $warnkids=0;