#1 2021-12-16 08:05:59

profh
Member
Registered: 2010-07-02
Posts: 161

about TSqlDataBase.LockJson

hi, ab:

  is it possibly to change TSqlDataBase.LockJson in mormot.db.raw.sqlite3.pas code as follow:

from:

  fSafe.Lock; // cache access is also protected by fSafe
  try
    if IsCacheable(aSql) then
    begin
      result := fCache.Find(aSql, aResultCount); // try to get JSON result from cache
      if result <> '' then
      begin
        if fLog <> nil then
        begin
          fLog.Add.Log(sllSQL, 'from cache % %', [FileNameWithoutPath, aSql], self);
          fLog.Add.Log(sllResult, result, self, fLogResultMaximumSize);
        end;
        fSafe.UnLock; // found in cache -> leave critical section                                                        <-------- from here
      end;
    end
    else
    begin
      // UPDATE, INSERT or any non SELECT statement
      CacheFlush;
      result := '';
    end;
  except
    ...;
  end;

to

  fSafe.Lock; // cache access is also protected by fSafe
  try
    if IsCacheable(aSql) then
    begin
      result := fCache.Find(aSql, aResultCount); // try to get JSON result from cache
      if result <> '' then
      begin
        if fLog <> nil then
        begin
          fLog.Add.Log(sllSQL, 'from cache % %', [FileNameWithoutPath, aSql], self);
          fLog.Add.Log(sllResult, result, self, fLogResultMaximumSize);
        end;
      end;
    end
    else
    begin
      // UPDATE, INSERT or any non SELECT statement
      CacheFlush;
      result := '';
    end;
  except
    ...;
  end;
  fSafe.UnLock; // found in cache -> leave critical section                                               <-------         to here

thanks for your great job!

Offline

#2 2021-12-16 08:49:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,656
Website

Re: about TSqlDataBase.LockJson

I don't think so: caller is responsible for calling UnLockJson if the function returns '', i.e. the result was not found in cache.

Please follow the forum rules and don't post code here in the forum.
A github pull request is easier to follow and merge.

Online

#3 2021-12-17 01:37:11

profh
Member
Registered: 2010-07-02
Posts: 161

Re: about TSqlDataBase.LockJson

Please follow the forum rules and don't post code here in the forum.

sorry about that.  smile

already got to run, thanks again!

Offline

Board footer

Powered by FluxBB