Index: src/json_timeline.c ================================================================== --- src/json_timeline.c +++ src/json_timeline.c @@ -135,11 +135,11 @@ ** to. ** ** Returns a positive value if it modifies pSql, 0 if it ** does not. It returns a negative value if the tag ** provided to the request was not found (pSql is not modified -** in that case. +** in that case). ** ** If payload is not NULL then on success its "tag" or "branch" ** property is set to the tag/branch name found in the request. ** ** Only one of "tag" or "branch" modes will work at a time, and if @@ -233,12 +233,11 @@ ** environment parameters. If it can it returns that value, ** else it returns some statically defined default value. ** ** Never returns a negative value. 0 means no limit. */ -static int json_timeline_limit(){ - static const int defaultLimit = 20; +static int json_timeline_limit(int defaultLimit){ int limit = -1; if(!g.isHTTP){/* CLI mode */ char const * arg = find_option("limit","n",1); if(arg && *arg){ limit = atoi(arg); @@ -275,12 +274,12 @@ blob_appendf(pSql, " AND event.type IN(%Q) ", zEventType); if( json_timeline_add_tag_branch_clause(pSql, pPayload) < 0 ){ return FSL_JSON_E_INVALID_ARGS; } json_timeline_add_time_clause(pSql); - limit = json_timeline_limit(); - if(limit>=0){ + limit = json_timeline_limit(20); + if(limit>0){ blob_appendf(pSql,"LIMIT %d ",limit); } if(pPayload){ cson_object_set(pPayload, "limit", json_new_int(limit)); } @@ -353,10 +352,11 @@ static cson_value * json_timeline_branch(){ cson_value * pay = NULL; Blob sql = empty_blob; Stmt q = empty_Stmt; + int limit = 0; if(!g.perm.Read){ json_set_err(FSL_JSON_E_DENIED, "Requires 'o' permissions."); return NULL; } @@ -378,10 +378,14 @@ " AND event.type='ci'" " AND blob.rid IN (SELECT rid FROM tagxref" " WHERE tagtype>0 AND tagid=%d AND srcid!=0)" " ORDER BY event.mtime DESC", TAG_BRANCH); + limit = json_timeline_limit(20); + if(limit>0){ + blob_appendf(&sql," LIMIT %d ",limit); + } db_prepare(&q,"%s", blob_str(&sql)); blob_reset(&sql); pay = json_stmt_to_array_of_obj(&q, NULL); db_finalize(&q); assert(NULL != pay); @@ -395,14 +399,13 @@ unsigned int i = 0; unsigned int len = cson_array_length_get(ar); for( ; i < len; ++i ){ cson_object * row = cson_value_get_object(cson_array_get(ar,i)); int rid = cson_value_get_integer(cson_object_get(row,"rid")); - if(row>0) { - cson_object_set_s(row, tags, json_tags_for_checkin_rid(rid,0)); - cson_object_set_s(row, isLeaf, json_value_to_bool(cson_object_get(row,"isLeaf"))); - } + assert( rid > 0 ); + cson_object_set_s(row, tags, json_tags_for_checkin_rid(rid,0)); + cson_object_set_s(row, isLeaf, json_value_to_bool(cson_object_get(row,"isLeaf"))); } cson_value_free( cson_string_value(tags) ); cson_value_free( cson_string_value(isLeaf) ); } return pay; @@ -454,27 +457,10 @@ #endif db_multi_exec(blob_buffer(&sql)); blob_reset(&sql); db_prepare(&q, "SELECT " " rid AS rid" -#if 0 - " uuid AS uuid," - " mtime AS timestamp," -# if 0 - " timestampString AS timestampString," -# endif - " comment AS comment, " - " user AS user," - " isLeaf AS isLeaf," /*FIXME: convert to JSON bool */ - " bgColor AS bgColor," /* why always null? */ - " eventType AS eventType" -# if 0 - " tags AS tags" - /*tagId is always null?*/ - " tagId AS tagId" -# endif -#endif " FROM json_timeline" " ORDER BY rowid"); listV = cson_value_new_array(); list = cson_value_get_array(listV); tmp = listV;