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 $cols = db::get_columns( $dbh, 'calcms_audio_recordings' );
my $columns = {};
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
return { map { $_ => undef } @$cols };
}
# get playout entries

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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