use map instead for on creating hash tables

This commit is contained in:
Milan
2020-03-05 22:16:54 +01:00
parent da5f7f673d
commit 41b0495c2e
24 changed files with 40 additions and 144 deletions

View File

@@ -23,11 +23,7 @@ sub get_columns($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_audio_recordings' ); my $cols = db::get_columns( $dbh, 'calcms_audio_recordings' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
# get playout entries # get playout entries

View File

@@ -164,10 +164,7 @@ sub get($$) {
exclude_locations => 1, exclude_locations => 1,
} }
); );
my $used_day = {}; my $used_day = { map { $_->{start_date} => 1 } @$used_days };
for my $day (@$used_days) {
$used_day->{ $day->{start_date} } = 1;
}
for my $year ( sort { $a <=> $b } keys %$years ) { for my $year ( sort { $a <=> $b } keys %$years ) {
my $months = $years->{$year}; my $months = $years->{$year};

View File

@@ -390,12 +390,7 @@ sub get_events($$$$) {
my $params = $request->{params}->{checked}->{comment}; my $params = $request->{params}->{checked}->{comment};
#get event_ids from comments #get event_ids from comments
my $event_ids = {}; my $event_ids = { map { $_->{event_id} => 1 } @$comments };
for my $comment (@$comments) {
my $event_id = $comment->{event_id};
$event_ids->{$event_id} = 1;
}
my @keys = keys %{$event_ids}; my @keys = keys %{$event_ids};
#get events from comment's event ids #get events from comment's event ids
return [] if ( scalar @keys ) == 0; return [] if ( scalar @keys ) == 0;

View File

@@ -191,10 +191,7 @@ sub extractMeta ($$) {
if ( defined $comments ) { if ( defined $comments ) {
#build index for meta already defined #build index for meta already defined
my $meta_keys = {}; my $meta_keys = { map { $_->{name}."=".$_->{value} => 1 } @$meta };
for my $pair (@$meta) {
$meta_keys->{ $pair->{name} . '=' . $pair->{value} } = 1;
}
while ( $comments =~ /\~\~META\:(.+?)\=(.+?)\~\~/g ) { while ( $comments =~ /\~\~META\:(.+?)\=(.+?)\~\~/g ) {
my $name = $1; my $name = $1;

View File

@@ -125,11 +125,7 @@ sub get_columns_hash($$) {
my $table = shift; my $table = shift;
my $columns = db::get_columns( $dbh, $table ); my $columns = db::get_columns( $dbh, $table );
my $result = {}; return { map { $_ => 1 } @$columns };
for my $column (@$columns) {
$result->{$column} = 1;
}
return $result;
} }
#returns last inserted id #returns last inserted id

View File

@@ -16,11 +16,7 @@ sub get_columns ($){
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_event_history' ); my $cols = db::get_columns( $dbh, 'calcms_event_history' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
sub get ($$){ sub get ($$){

View File

@@ -23,11 +23,7 @@ sub get_columns ($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_password_requests' ); my $cols = db::get_columns( $dbh, 'calcms_password_requests' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
sub get ($$) { sub get ($$) {

View File

@@ -20,11 +20,7 @@ sub get_columns ($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_playout' ); my $cols = db::get_columns( $dbh, 'calcms_playout' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }

View File

@@ -30,11 +30,7 @@ sub get_columns ($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_projects' ); my $cols = db::get_columns( $dbh, 'calcms_projects' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
# get projects # get projects

View File

@@ -34,11 +34,7 @@ sub get_columns ($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_series' ); my $cols = db::get_columns( $dbh, 'calcms_series' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
# get series content # get series content
@@ -772,14 +768,14 @@ sub get_images ($$) {
series_id => $options->{series_id} series_id => $options->{series_id}
} }
); );
my $images = {}; my $images = {
my $found = 0; map {
for my $event (@$events) { my $image = $_->{image};
my $image = $event->{image}; $image =~ s/.*\///;
$image =~ s/.*\///; { $image => 1 };
$images->{$image} = 1; } @$events
$found++; };
} my $found = scalar(keys %$images);
return undef if $found == 0; return undef if $found == 0;
@@ -948,10 +944,7 @@ sub set_event_ids ($$$$$) {
return unless defined $event_ids; return unless defined $event_ids;
#make lookup table from events #make lookup table from events
my $event_id_hash = {}; my $event_id_hash = { map { $_ => 1 } @$event_ids };
for my $event_id (@$event_ids) {
$event_id_hash->{$event_id} = 1;
}
#get series_entries from db #get series_entries from db
#my $bind_names=join(',', (map { '?' } @$event_ids)); #my $bind_names=join(',', (map { '?' } @$event_ids));
@@ -964,16 +957,8 @@ sub set_event_ids ($$$$$) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $results = db::get( $dbh, $query, $bind_values ); my $results = db::get( $dbh, $query, $bind_values );
my $found = {};
#mark events found assigned to series #mark events found assigned to series
my $i = 1; my $found = { map { $_->{event_id} => 1 } @$results };
for my $event (@$results) {
#print "found event $i: $event->{event_id}\n";
$found->{ $event->{event_id} } = 1;
$i++;
}
#insert events from list, not found in db #insert events from list, not found in db
for my $event_id (@$event_ids) { for my $event_id (@$event_ids) {

View File

@@ -26,11 +26,7 @@ sub get_columns ($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_series_dates' ); my $cols = db::get_columns( $dbh, 'calcms_series_dates' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
# get all series_dates for studio_id and series_id within given time range # get all series_dates for studio_id and series_id within given time range
@@ -261,12 +257,8 @@ sub addSeriesScheduleAttributes ($$) {
my $config = shift; my $config = shift;
my $entries = shift; my $entries = shift;
my $scheduleIds = {};
# get series schedule ids used at entries # get series schedule ids used at entries
for my $entry (@$entries) { my $scheduleIds = { map { $_->{series_schedule_id} => 1 } @$entries };
$scheduleIds->{ $entry->{series_schedule_id} } = 1;
}
my @scheduleIds = keys %$scheduleIds; my @scheduleIds = keys %$scheduleIds;
return $entries if scalar(@scheduleIds) == 0; return $entries if scalar(@scheduleIds) == 0;

View File

@@ -41,7 +41,7 @@ sub save_content($$) {
my $config = shift; my $config = shift;
my $entry = shift; my $entry = shift;
return undef unless ( defined $entry->{id} ); return undef unless defined $entry->{id};
for my $attr ( keys %$entry ) { for my $attr ( keys %$entry ) {
next unless defined $entry->{$attr}; next unless defined $entry->{$attr};
@@ -308,10 +308,7 @@ sub check_permission($$) {
delete $options->{permission}; delete $options->{permission};
#convert check list to hash #convert check list to hash
my $check = {}; my $check = { map { $_ => 1 } @{ $options->{check_for} } };
for my $permission ( @{ $options->{check_for} } ) {
$check->{$permission} = 1;
}
delete $options->{check_for}; delete $options->{check_for};
# is project assigned to studio # is project assigned to studio

View File

@@ -28,11 +28,8 @@ sub get_columns ($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_series_schedule' ); my $cols = db::get_columns( $dbh, 'calcms_series_schedule' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
#map schedule id to id #map schedule id to id

View File

@@ -22,11 +22,7 @@ sub get_columns ($){
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_studio_timeslot_dates' ); my $cols = db::get_columns( $dbh, 'calcms_studio_timeslot_dates' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
# get all studio_timeslot_dates for studio_id within given time range # get all studio_timeslot_dates for studio_id within given time range

View File

@@ -20,11 +20,7 @@ sub get_columns($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_studio_timeslot_schedule' ); my $cols = db::get_columns( $dbh, 'calcms_studio_timeslot_schedule' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
#map schedule id to id #map schedule id to id

View File

@@ -17,11 +17,7 @@ sub get_columns($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_studios' ); my $cols = db::get_columns( $dbh, 'calcms_studios' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
sub get($;$) { sub get($;$) {
my $config = shift; my $config = shift;

View File

@@ -16,13 +16,9 @@ sub debug;
sub get_columns($) { sub get_columns($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_user_default_studios' ); my $cols = db::get_columns( $dbh, 'calcms_user_default_studios' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
sub get ($$) { sub get ($$) {

View File

@@ -28,11 +28,7 @@ sub get_columns($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_user_sessions' ); my $cols = db::get_columns( $dbh, 'calcms_user_sessions' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
#map schedule id to id #map schedule id to id

View File

@@ -138,11 +138,7 @@ sub get_columns($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_user_settings' ); my $cols = db::get_columns( $dbh, 'calcms_user_settings' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
sub get ($$) { sub get ($$) {

View File

@@ -15,11 +15,7 @@ sub get_columns($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_user_stats' ); my $cols = db::get_columns( $dbh, 'calcms_user_stats' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
sub get ($$) { sub get ($$) {
@@ -205,7 +201,7 @@ sub increase ($$$) {
return undef unless defined $options->{user}; return undef unless defined $options->{user};
my $columns = get_columns($config); my $columns = get_columns($config);
return undef unless defined $columns->{$usecase}; return undef unless exists $columns->{$usecase};
my $entries = get( $config, $options ); my $entries = get( $config, $options );
if ( scalar @$entries == 0 ) { if ( scalar @$entries == 0 ) {

View File

@@ -26,11 +26,7 @@ sub get_columns($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_work_dates' ); my $cols = db::get_columns( $dbh, 'calcms_work_dates' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
# get all work_dates for studio_id and schedule_id within given time range # get all work_dates for studio_id and schedule_id within given time range

View File

@@ -27,11 +27,7 @@ sub get_columns($) {
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_work_schedule' ); my $cols = db::get_columns( $dbh, 'calcms_work_schedule' );
my $columns = {}; return { map { $_ => undef } @$cols };
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
} }
#map schedule id to id #map schedule id to id

View File

@@ -237,11 +237,7 @@ sub show_projects {
$project->{pid} = $project->{project_id}; $project->{pid} = $project->{project_id};
# get assigned studios by id # get assigned studios by id
my $assigned_studio_by_id = {}; my $assigned_studio_by_id = { map { $_->{studio_id} => 1 } @$project_studio_assignements };
for my $studio (@$project_studio_assignements) {
$assigned_studio_by_id->{ $studio->{studio_id} } = 1;
}
my $assigned_studios = []; my $assigned_studios = [];
my $unassigned_studios = []; my $unassigned_studios = [];
for my $studio (@$studios) { for my $studio (@$studios) {

View File

@@ -333,7 +333,7 @@ sub save_series {
# fill series entry # fill series entry
my $entry = {}; my $entry = {};
for my $param ( keys %$params ) { for my $param ( keys %$params ) {
if ( defined $columns->{$param} ) { if ( exists $columns->{$param} ) {
$entry->{$param} = $params->{$param} || ''; $entry->{$param} = $params->{$param} || '';
} }
} }