<commit_before># --
# Kernel/Output/HTML/DashboardRSS.pm
# Copyright (C) 2001-2009 OTRS AG, http://otrs.org/
# --
# $Id: DashboardRSS.pm,v 1.5 2009-06-12 20:25:02 martin Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

package Kernel::Output::HTML::DashboardRSS;

use strict;
use warnings;

use XML::FeedPP;
use Kernel::System::Cache;

use vars qw($VERSION);
$VERSION = qw($Revision: 1.5 $) [1];

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {%Param};
    bless( $Self, $Type );

    # get needed objects
    for (qw(Config Name ConfigObject LogObject DBObject LayoutObject ParamObject TicketObject UserID)) {
        die "Got no $_!" if ( !$Self->{$_} );
    }

    $Self->{CacheObject} = Kernel::System::Cache->new(%Param);

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;

    # check cache
    my $Content = '';
    if ( $Self->{Config}->{CacheTTL} ) {
        $Content = $Self->{CacheObject}->Get(
            Type => 'DashboardRSS',
            Key  => $Self->{Config}->{URL},
        );
    }

    # get content
    if ( !$Content ) {
        my $Feed = XML::FeedPP->new( $Self->{Config}->{URL} );

        my $Count = 0;
        for my $Item ( $Feed->get_item() ) {
            $Count++;
            last if $Count > $Self->{Config}->{Limit};
            my $Time = $Item->pubDate();
            my $Ago;
            if ($Time) {
                my $SystemTime = $Self->{TimeObject}->TimeStamp2SystemTime(
                    String => $Time,
                );
                $Ago = $Self->{TimeObject}->SystemTime() - $SystemTime;
                $Ago = $Self->{LayoutObject}->CustomerAge(
                    Age   => $Ago,
                    Space => ' ',
                );
            }

            $Self->{LayoutObject}->Block(
                Name => 'ContentSmallRSSOverviewRow',
                Data => {
                    Title => $Item->title(),
                    Link  => $Item->link(),
                    Ago   => $Ago,
                },
            );
        }

        $Content = $Self->{LayoutObject}->Output(
            TemplateFile => 'AgentDashboardRSSOverview',
            Data         => {
                %{ $Self->{Config} },
            },
        );

        # cache
        if ( $Self->{Config}->{CacheTTL} ) {
            $Self->{CacheObject}->Set(
                Type  => 'DashboardRSS',
                Key   => $Self->{Config}->{URL},
                Value => $Content,
                TTL   => $Self->{Config}->{CacheTTL} * 60,
            );
        }
    }

    $Self->{LayoutObject}->Block(
        Name => 'ContentSmall',
        Data => {
            %{ $Self->{Config} },
            Name    => $Self->{Name},
            Content => $Content,
        },
    );

    return 1;
}

1;
<commit_msg>Improved cache feature.<commit_after># --
# Kernel/Output/HTML/DashboardRSS.pm
# Copyright (C) 2001-2009 OTRS AG, http://otrs.org/
# --
# $Id: DashboardRSS.pm,v 1.6 2009-06-12 21:30:37 martin Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

package Kernel::Output::HTML::DashboardRSS;

use strict;
use warnings;

use XML::FeedPP;
use Kernel::System::Cache;

use vars qw($VERSION);
$VERSION = qw($Revision: 1.6 $) [1];

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {%Param};
    bless( $Self, $Type );

    # get needed objects
    for (qw(Config Name ConfigObject LogObject DBObject LayoutObject ParamObject TicketObject UserID)) {
        die "Got no $_!" if ( !$Self->{$_} );
    }

    $Self->{CacheObject} = Kernel::System::Cache->new(%Param);

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;

    # check cache
    my $CacheKey = $Self->{Config}->{URL} . '-' . $Self->{LayoutObject}->{UserLanguage};
    my $Content = '';
    if ( $Self->{Config}->{CacheTTL} ) {
        $Content = $Self->{CacheObject}->Get(
            Type => 'DashboardRSS',
            Key  => $CacheKey,
        );
    }

    # get content
    if ( !$Content ) {
        my $Feed = XML::FeedPP->new( $Self->{Config}->{URL} );

        my $Count = 0;
        for my $Item ( $Feed->get_item() ) {
            $Count++;
            last if $Count > $Self->{Config}->{Limit};
            my $Time = $Item->pubDate();
            my $Ago;
            if ($Time) {
                my $SystemTime = $Self->{TimeObject}->TimeStamp2SystemTime(
                    String => $Time,
                );
                $Ago = $Self->{TimeObject}->SystemTime() - $SystemTime;
                $Ago = $Self->{LayoutObject}->CustomerAge(
                    Age   => $Ago,
                    Space => ' ',
                );
            }

            $Self->{LayoutObject}->Block(
                Name => 'ContentSmallRSSOverviewRow',
                Data => {
                    Title => $Item->title(),
                    Link  => $Item->link(),
                    Ago   => $Ago,
                },
            );
        }

        $Content = $Self->{LayoutObject}->Output(
            TemplateFile => 'AgentDashboardRSSOverview',
            Data         => {
                %{ $Self->{Config} },
            },
        );

        # cache
        if ( $Self->{Config}->{CacheTTL} ) {
            $Self->{CacheObject}->Set(
                Type  => 'DashboardRSS',
                Key   => $CacheKey,
                Value => $Content,
                TTL   => $Self->{Config}->{CacheTTL} * 60,
            );
        }
    }

    $Self->{LayoutObject}->Block(
        Name => 'ContentSmall',
        Data => {
            %{ $Self->{Config} },
            Name    => $Self->{Name},
            Content => $Content,
        },
    );

    return 1;
}

1;

{'fraction_non_alphanumeric': 0.16812696313440237, 'fraction_numerical': 0.010910894362704579, 'mean_word_length': 1.5733730327520203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4991470', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1876, 'n_words': 396}