From 1a51b1adc7d93ef9bf020844fb4798d55a3646bd Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Fri, 17 Feb 2012 05:19:24 +0000 Subject: [PATCH] added: to config: parameter: ezc_max_elements maximum number for elements through the whole template (ezc) default: 50000 parameter: ezc_max_loop_elements maximum number of each [for] loop default: 5000 (from ezc generator) added: to Request class: time_t start_time; tm start_tm; they are set when a request starts git-svn-id: svn://ttmath.org/publicrep/winix/trunk@806 e52654a7-88a9-db11-a3e9-0013d4bc506e --- core/app.cpp | 1 + core/config.cpp | 4 ++++ core/config.h | 10 ++++++++++ core/item.cpp | 6 +++++- core/request.cpp | 13 +++++++++++++ core/request.h | 8 +++++++- functions/Makefile.dep | 6 ++++++ plugins/thread/templates.cpp | 1 + templates/insert.cpp | 1 + templates/item.cpp | 2 ++ templates/templates.cpp | 5 +++++ 11 files changed, 55 insertions(+), 2 deletions(-) diff --git a/core/app.cpp b/core/app.cpp index d51041d..fb57ad9 100755 --- a/core/app.cpp +++ b/core/app.cpp @@ -265,6 +265,7 @@ void App::ProcessRequest() { try { + cur.request->RequestStarts(); system.load_avg.StartRequest(); log << log2 << config.log_delimiter << logend; diff --git a/core/config.cpp b/core/config.cpp index be12ea5..4f661c0 100755 --- a/core/config.cpp +++ b/core/config.cpp @@ -230,6 +230,10 @@ void Config::AssignValues(bool stdout_is_closed) content_type_header = Int(L"content_type_header", 0); umask = Int(L"umask", 0222); + + ezc_max_elements = Size(L"ezc_max_elements", 50000); + ezc_max_loop_elements = Size(L"ezc_max_loop_elements", 5000); + } diff --git a/core/config.h b/core/config.h index 4060bcc..28a0118 100755 --- a/core/config.h +++ b/core/config.h @@ -459,6 +459,16 @@ public: int umask; + // maximum number for elements through the whole template + // default: 50000 + size_t ezc_max_elements; + + // maximum number of each [for] loop + // default: 5000 (from ezc generator) + size_t ezc_max_loop_elements; + + + Config(); bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true); diff --git a/core/item.cpp b/core/item.cpp index 86192ee..73bedd6 100755 --- a/core/item.cpp +++ b/core/item.cpp @@ -2,7 +2,7 @@ * This file is a part of Winix * and is not publicly distributed * - * Copyright (c) 2010-2011, Tomasz Sowa + * Copyright (c) 2010-2012, Tomasz Sowa * All rights reserved. * */ @@ -19,6 +19,10 @@ Item::Item() } +// !! IMPROVE ME +// now we have Request::start_time and Request::start_tm +// we can somehow get the current time from the request +// may setting the date should be completetly removed from here? void Item::SetDateToNow() { date_creation = Time(std::time(0)); diff --git a/core/request.cpp b/core/request.cpp index a30833f..f063706 100755 --- a/core/request.cpp +++ b/core/request.cpp @@ -84,10 +84,23 @@ void Request::Clear() send_as_attachment = false; using_ssl = false; + + start_time = 0; + memset(&start_tm, 0, sizeof(start_tm)); } +void Request::RequestStarts() +{ + // clearing it is better to use at the end of a request + // so starting is much faster + + start_time = std::time(0); + start_tm = Time(start_time); +} + + // value can be null void Request::SetCookie(const char * name, const char * value, tm * expires) diff --git a/core/request.h b/core/request.h index 8662926..5e7c459 100755 --- a/core/request.h +++ b/core/request.h @@ -130,12 +130,18 @@ struct Request // this is a pointer either to the item (if exists) or to the last directory Item * last_item; + // request start time + // Time() methods are very slow so it is better to directly use those two values + // they are set when a request starts + time_t start_time; + tm start_tm; + Request(); void SetConfig(Config * pconfig); + void RequestStarts(); void Clear(); - bool IsParam(const wchar_t * param_name); diff --git a/functions/Makefile.dep b/functions/Makefile.dep index ee61ac6..b469f32 100755 --- a/functions/Makefile.dep +++ b/functions/Makefile.dep @@ -519,6 +519,12 @@ logout.o: ../templates/htmltextstream.h ../core/mounts.h logout.o: ../core/mountparser.h ../core/crypt.h ../core/users.h logout.o: ../core/groups.h ../core/group.h ../core/loadavg.h ../core/image.h logout.o: ../core/basethread.h ../core/threadmanager.h ../core/synchro.h +logout.o: ../core/plugin.h ../core/pluginmsg.h ../core/system.h +logout.o: ../core/sessionmanager.h ../core/sessioncontainer.h +logout.o: ../functions/functions.h ../templates/templates.h +logout.o: ../templates/patterncacher.h ../templates/indexpatterns.h +logout.o: ../templates/patterns.h ../templates/changepatterns.h +logout.o: ../core/sessionmanager.h ls.o: ls.h functionbase.h ../core/item.h ../db/db.h ../db/dbbase.h ls.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h ../core/misc.h ls.o: ../core/item.h ../core/requesttypes.h ../core/error.h diff --git a/plugins/thread/templates.cpp b/plugins/thread/templates.cpp index 0e0b29a..c192bdc 100755 --- a/plugins/thread/templates.cpp +++ b/plugins/thread/templates.cpp @@ -331,6 +331,7 @@ void thread_sort_tab_run(Info & i) Ezc::Pattern * p = pattern_cacher.GetPattern(*thread_info.item_sort_tab[item_sort_index]); item_run_content.Clear(); + ezc_generator.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements); ezc_generator.Generate(item_run_content, *p); item_print_content(i.out, item_run_content.Str(), thread_info.item_sort_tab[item_sort_index]->content_type); diff --git a/templates/insert.cpp b/templates/insert.cpp index 30e0332..f4f3049 100755 --- a/templates/insert.cpp +++ b/templates/insert.cpp @@ -45,6 +45,7 @@ void insert_page_run(Info & i) insert_page_cur += 1; info.run_content.Clear(); + info.ezc_gen.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements); info.ezc_gen.Generate(info.run_content, *pat); item_print_content(i.out, info.run_content.Str(), info.item.content_type); diff --git a/templates/item.cpp b/templates/item.cpp index 58ee2d7..44a22c3 100755 --- a/templates/item.cpp +++ b/templates/item.cpp @@ -292,6 +292,7 @@ void item_run(Info & i) Ezc::Pattern * p = pattern_cacher.GetPattern(cur->request->item); item_run_content.Clear(); + ezc_generator.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements); ezc_generator.Generate(item_run_content, *p); item_print_content(i.out, item_run_content.Str(), cur->request->item.content_type); @@ -652,6 +653,7 @@ void item_tab_run(Info & i) { Ezc::Pattern * p = pattern_cacher.GetPattern(cur->request->item_tab[item_index]); item_run_content.Clear(); + ezc_generator.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements); ezc_generator.Generate(item_run_content, *p); item_print_content(i.out, item_run_content.Str(), cur->request->item_tab[item_index].content_type); } diff --git a/templates/templates.cpp b/templates/templates.cpp index 4c23471..2390f28 100755 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -122,9 +122,14 @@ Ezc::Pattern * p = 0; if( p ) + { + content_gen.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements); content_gen.Generate(i.out, *p); + } else + { log << log1 << "Templates: content: there are not any patterns"; + } }