anchor.diff:  
   %% @doc Rebuild the search index by queueing all resources for pivot.
   queue_all(Context) ->
  -    z_db:q("UPDATE rsc SET version=version+1", Context).
  -
  +    erlang:spawn(fun() ->
  +                    queue_all(0, Context)
  +                 end).
  +
  +    queue_all(FromId, Context) ->
  +        case z_db:q("select id from rsc where id > $1 order by id limit 1000", [FromId], Context) of
  +            [] ->
  +                done;
  +            Ids ->
  +                F = fun(Ctx) ->
  +                        [ insert_queue(Id, Ctx) || {Id} <- Ids ]
  +                    end,
  +                z_db:transaction(F, Context),
  +                {LastId} = lists:last(Ids),
  +                queue_all(LastId, Context)
  +        end.
  +                
  +%% @doc Insert a rsc_id in the pivot queue
  +insert_queue(Id, Context) ->
  +    case z_db:q("update rsc_pivot_queue 
  +                 set serial = serial + 1
  +                 where rsc_id = $1", [Id], Context) of
  +        1 -> ok;
  +        0 -> z_db:q("insert into rsc_pivot_queue (rsc_id, due, is_update) values ($1, now(), true)", [Id], Context)
  +    end.
  +    
   
   %% @doc Insert a slow running pivot task. For example syncing category numbers after an category update.
   insert_task(Module, Function, Context) ->
  -	insert_task(Module, Function, z_ids:id(), [], Context).
  +    insert_task(Module, Function, z_ids:id(), [], Context).
   
   %% @doc Insert a slow running pivot task. Use the UniqueKey to prevent double queued tasks.
   insert_task(Module, Function, UniqueKey, Context) ->
  -	insert_task(Module, Function, UniqueKey, [], Context).
  -	
  +    insert_task(Module, Function, UniqueKey, [], Context).
  +    
   %% @doc Insert a slow running pivot task with unique key and arguments.
   insert_task(Module, Function, UniqueKey, Args, Context) ->
  -	z_db:transaction(fun(Ctx) -> insert_transaction(Module, Function, UniqueKey, Args, Ctx) end, Context).
  -
  -	insert_transaction(Module, Function, UniqueKey, Args, Context) ->
  -		Fields = [
  -			{module, Module},
  -			{function, Function},
  -			{key, UniqueKey},
  -			{args, Args}
  -		],
  -		case z_db:q1("select id from pivot_task_queue where module = $1 and function = $2 and key = $3", 
  -					[Module, Function, UniqueKey], Context) of
  -			undefined -> z_db:insert(pivot_task_queue, Fields, Context);
  -			Id -> {ok, Id}
  -		end.
  +    z_db:transaction(fun(Ctx) -> insert_transaction(Module, Function, UniqueKey, Args, Ctx) end, Context).
  +
  +    insert_transaction(Module, Function, UniqueKey, Args, Context) ->
  +        Fields = [
  +            {module, Module},
  +            {function, Function},
  +            {key, UniqueKey},
  +            {args, Args}
  +        ],
  +        case z_db:q1("select id from pivot_task_queue where module = $1 and function = $2 and key = $3", 
  +                    [Module, Function, UniqueKey], Context) of
  +            undefined -> z_db:insert(pivot_task_queue, Fields, Context);
  +            Id -> {ok, Id}
  +        end.
   
   
   
  
positive.code: %% get_pivot_data {objids, catids, [ta,tb,tc,td]}
  get_pivot_data(Id, Context) ->
      Rsc = m_rsc:get(Id, Context),
  	R = z_notifier:foldr({pivot_get, Id}, Rsc, Context),
      {A,B} = lists:foldl(fun fetch_texts/2, {[],[]}, R),
      {ObjIds, ObjTexts} = related(Id, Context),
      {CatIds, CatTexts} = category(proplists:get_value(category_id, R), Context),
      Split = [ (split_lang(Ts, Context)) || Ts <- [A, B, CatTexts, ObjTexts] ],
  
negative.code:                     ?LOG("Task failed(~p:~p): ~p:~p(~p)~n", [Error, Reason, Module, Function, Args]),
                      insert_task(Module, Function, Key, Args, Context)
              end;
          empty ->
              nop
      end,
      % Pivot some resources
      case fetch_queue(Context) of
          [] -> ok;
          Qs ->
              F = fun(Ctx) ->
                          [ pivot_resource(Id, Ctx) || {Id,_Serial} <- Qs]
                  end,
              case z_db:transaction(F, Context) of
                  {rollback, PivotError} -> ?LOG("Pivot error: ~p~n", [PivotError]);
                  L when is_list(L) -> delete_queue(Qs, Context)
              end
      end.
  
  
      %% @doc Fetch the next task uit de task queue, if any.
      poll_task(Context) ->
          case z_db:q_row("select id, module, function, key, props from pivot_task_queue order by id asc limit 1", Context) of
              {Id,Module,Function,Key,Props} ->
                  Args = case Props of
                      [{args,Args0}] -> Args0;
                      _ -> []
                  end,
                  %% @todo We delete the task right now, this needs to be changed to a deletion after the task has been running.
                  z_db:q("delete from pivot_task_queue where id = $1", [Id], Context),
                  {z_convert:to_atom(Module), z_convert:to_atom(Function), Key, Args};
              undefined ->
                  empty
          end.
      
  
  %% @doc Pivot a specific id, delete its queue record if present
  do_pivot(Id, Context) ->
  