cancel
Showing results for 
Search instead for 
Did you mean: 

Issue when writting on files

ediez
Champ in-the-making
Champ in-the-making
Hi,

I'm calling a set of methods from the Javascript API to create and write on a text file.

I'm adding a new entry to a text file on a loop, the thing is that every time I write on the file, a new file is being created in the repository. The file has almost 11.000 entries, so that would mean over 10.000 files in my repository.

Does anyone know which method I should call in order to avoid this?

Here's the code snipped.


// log the docs that currently contain the word 'Alfresco' to a log file
var logFile = userhome.childByNamePath("alf docs.txt");
if (logFile == null)
{
   logFile = userhome.createFile("alf docs.txt");
}
if (logFile != null)
{
   // execute a lucene search across the repo for the text 'alfresco'
   var docs = search.luceneSearch("TEXT:alfresco");
   var log = "";
   for (var i=0; i<docs.length; i++)
   {
      log += "Name: " + docs.name + "\tPath: " + docs.displayPath + "\r\n";
   }
   logFile.content += log;
}
3 REPLIES 3

stebans
Champ in-the-making
Champ in-the-making
Hi,

I've been facing the same kind of situation noting that a log file was recreated each time I wad making a change to it. I'm just aware of this problem, but I know orphan content is to be cleaned up some time (see http://wiki.alfresco.com/wiki/Content_Store_Configuration see ContentStoreCleaner). I guess it has to do with the protectDays property, but haven't experienced with it myself.

HTH,
Best regards,
Stéphane

ediez
Champ in-the-making
Champ in-the-making
Stéphane, Thanks a lot for replying.

One question: Did you manage to resolve this issue?. The way I see it, this method will delete the orphan nodes but, I will still have the problem of the files being recreated.

sacco
Champ in-the-making
Champ in-the-making
Hmmm.  I can see why it's doing this but it does suggest that persisting content properties
automatically on every modification is not such a smart idea, or at least that there should
be some way to switch this feature off.

I suspect you will have to assemble (or at least batch) your entries in memory; this could
become a performance/resource problem if the number of entries is too large, but will
still probably be less of a problem than writing  10 000  files to disk.

You could do something like:

var docs = search.luceneSearch("TEXT:alfresco");
logFile.content = docs.map( function(element, index, array)
    { return  ("Name: " + element.name + "\tPath: " + element.displayPath); }
  ).join( "\r\n" );

or, if your JavaScript has the reduce method built in:

var docs = search.luceneSearch("TEXT:alfresco");
logFile.content = docs.reduce( function(previous, element, index, array)
  {return  (previous + "Name: " + element.name + "\tPath: " + element.displayPath + "\r\n");},
  "" );