mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-04-06 22:08:51 +00:00
Monotone-Parent: 21522597b7f1ca393730634622be7b92bb40bf5a
Monotone-Revision: cbba640dfc6321c0f4565ae72d616bc60cb20407 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2008-01-16T18:59:07 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
2008-01-16 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* GCSFolder.m: fetch the content, version and dates at the same
|
||||
time per record, to avoid multiple queries.
|
||||
|
||||
2007-12-12 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* GCSFolder.m ([GCSFolder -creationDateOfEntryWithName:]): new
|
||||
|
||||
@@ -104,11 +104,8 @@
|
||||
- (NSArray *)subFolderNames;
|
||||
- (NSArray *)allSubFolderNames;
|
||||
|
||||
- (NSNumber *)versionOfContentWithName:(NSString *)_name;
|
||||
- (NSCalendarDate *)creationDateOfEntryWithName:(NSString *)_name;
|
||||
- (NSCalendarDate *)lastModificationOfEntryWithName:(NSString *)_name;
|
||||
- (NSDictionary *) recordOfEntryWithName: (NSString *) name;
|
||||
|
||||
- (NSString *)fetchContentWithName:(NSString *)_name;
|
||||
- (NSException *)writeContent:(NSString *)_content toName:(NSString *)_name
|
||||
baseVersion:(unsigned int)_baseVersion;
|
||||
- (NSException *)writeContent:(NSString *)_content toName:(NSString *)_name;
|
||||
|
||||
@@ -251,15 +251,14 @@ static GCSStringFormatter *stringFormatter = nil;
|
||||
recursive:YES];
|
||||
}
|
||||
|
||||
- (id) _fetchValueOfColumn: (NSString *)_col
|
||||
inContentWithName: (NSString *)_name
|
||||
ignoreDeleted: (BOOL) ignoreDeleted
|
||||
- (NSDictionary *) _fetchValueOfColumns: (NSArray *) _cols
|
||||
inContentWithName: (NSString *) _name
|
||||
ignoreDeleted: (BOOL) ignoreDeleted
|
||||
{
|
||||
EOAdaptorChannel *channel;
|
||||
NSException *error;
|
||||
NSDictionary *row;
|
||||
NSArray *attrs;
|
||||
NSString *result;
|
||||
NSMutableString *sql;
|
||||
|
||||
if ((channel = [self acquireStoreChannel]) == nil) {
|
||||
@@ -271,12 +270,13 @@ static GCSStringFormatter *stringFormatter = nil;
|
||||
sql = [NSMutableString stringWithFormat: @"SELECT %@"
|
||||
@" FROM %@"
|
||||
@" WHERE c_name = '%@'",
|
||||
_col, [self storeTableName], _name];
|
||||
[_cols componentsJoinedByString: @","],
|
||||
[self storeTableName], _name];
|
||||
if (ignoreDeleted)
|
||||
[sql appendString: @" AND (c_deleted != 1 OR c_deleted IS NULL)"];
|
||||
|
||||
/* run SQL */
|
||||
|
||||
|
||||
if ((error = [channel evaluateExpressionX:sql]) != nil) {
|
||||
[self errorWithFormat:@"%s: cannot execute SQL '%@': %@",
|
||||
__PRETTY_FUNCTION__, sql, error];
|
||||
@@ -286,51 +286,64 @@ static GCSStringFormatter *stringFormatter = nil;
|
||||
|
||||
/* fetch results */
|
||||
|
||||
result = nil;
|
||||
attrs = [channel describeResults:NO /* do not beautify names */];
|
||||
if ((row = [channel fetchAttributes:attrs withZone:NULL]) != nil) {
|
||||
result = [[[row objectForKey:_col] copy] autorelease];
|
||||
if (![result isNotNull]) result = nil;
|
||||
row = [channel fetchAttributes: attrs withZone: NULL];
|
||||
if (row)
|
||||
[channel cancelFetch];
|
||||
}
|
||||
|
||||
/* release and return result */
|
||||
|
||||
[self releaseChannel:channel];
|
||||
return result;
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
- (NSNumber *)versionOfContentWithName:(NSString *)_name {
|
||||
return [self _fetchValueOfColumn:@"c_version" inContentWithName:_name
|
||||
ignoreDeleted: YES];
|
||||
- (NSDictionary *) recordOfEntryWithName: (NSString *) name
|
||||
{
|
||||
NSDictionary *row;
|
||||
NSMutableDictionary *record;
|
||||
NSArray *columns;
|
||||
NSString *strValue;
|
||||
int intValue;
|
||||
|
||||
columns = [NSArray arrayWithObjects: @"c_content", @"c_version",
|
||||
@"c_creationdate", @"c_lastmodified", nil];
|
||||
row = [self _fetchValueOfColumns: columns
|
||||
inContentWithName: name
|
||||
ignoreDeleted: YES];
|
||||
if (row)
|
||||
{
|
||||
record = [NSMutableDictionary dictionaryWithCapacity: 5];
|
||||
strValue = [row objectForKey: @"c_content"];
|
||||
if (![strValue isNotNull])
|
||||
strValue = @"";
|
||||
[record setObject: strValue forKey: @"c_content"];
|
||||
[record setObject: [row objectForKey: @"c_version"]
|
||||
forKey: @"c_version"];
|
||||
intValue = [[row objectForKey: @"c_creationdate"] intValue];
|
||||
[record
|
||||
setObject: [NSCalendarDate dateWithTimeIntervalSince1970: intValue]
|
||||
forKey: @"c_creationdate"];
|
||||
intValue = [[row objectForKey: @"c_lastmodified"] intValue];
|
||||
[record
|
||||
setObject: [NSCalendarDate dateWithTimeIntervalSince1970: intValue]
|
||||
forKey: @"c_lastmodified"];
|
||||
}
|
||||
else
|
||||
record = nil;
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
- (NSCalendarDate *)creationDateOfEntryWithName:(NSString *)_name {
|
||||
int seconds;
|
||||
- (NSNumber *) deletionOfEntryWithName: (NSString *) name
|
||||
{
|
||||
NSDictionary *row;
|
||||
|
||||
seconds = [[self _fetchValueOfColumn:@"c_creationdate" inContentWithName:_name
|
||||
ignoreDeleted: YES] intValue];
|
||||
row = [self _fetchValueOfColumns: [NSArray arrayWithObject: @"c_deleted"]
|
||||
inContentWithName: name
|
||||
ignoreDeleted: NO];
|
||||
|
||||
return [NSCalendarDate dateWithTimeIntervalSince1970: seconds];
|
||||
}
|
||||
|
||||
- (NSCalendarDate *)lastModificationOfEntryWithName:(NSString *)_name {
|
||||
int seconds;
|
||||
|
||||
seconds = [[self _fetchValueOfColumn:@"c_lastmodified" inContentWithName:_name
|
||||
ignoreDeleted: YES] intValue];
|
||||
|
||||
return [NSCalendarDate dateWithTimeIntervalSince1970: seconds];
|
||||
}
|
||||
|
||||
- (NSNumber *)deletionOfContentWithName:(NSString *)_name {
|
||||
return [self _fetchValueOfColumn:@"c_deleted" inContentWithName:_name
|
||||
ignoreDeleted: NO];
|
||||
}
|
||||
|
||||
- (NSString *)fetchContentWithName:(NSString *)_name {
|
||||
return [self _fetchValueOfColumn:@"c_content" inContentWithName:_name
|
||||
ignoreDeleted: YES];
|
||||
return [row objectForKey: @"c_deleted"];
|
||||
}
|
||||
|
||||
- (NSDictionary *)fetchContentsOfAllFiles {
|
||||
@@ -571,6 +584,7 @@ static GCSStringFormatter *stringFormatter = nil;
|
||||
{
|
||||
EOAdaptorChannel *storeChannel, *quickChannel;
|
||||
NSMutableDictionary *quickRow, *contentRow;
|
||||
NSDictionary *currentRow;
|
||||
GCSFieldExtractor *extractor;
|
||||
NSException *error;
|
||||
NSNumber *storedVersion;
|
||||
@@ -598,19 +612,24 @@ static GCSStringFormatter *stringFormatter = nil;
|
||||
if (doLogStore)
|
||||
[self logWithFormat:@"should store content: '%@'\n%@", _name, _content];
|
||||
|
||||
storedVersion = [self versionOfContentWithName:_name];
|
||||
currentRow = [self _fetchValueOfColumns: [NSArray arrayWithObjects:
|
||||
@"c_version",
|
||||
@"c_deleted", nil]
|
||||
inContentWithName: _name
|
||||
ignoreDeleted: NO];
|
||||
storedVersion = [currentRow objectForKey: @"c_version"];
|
||||
if (doLogStore)
|
||||
[self logWithFormat:@" version: %@", storedVersion];
|
||||
isNewRecord = [storedVersion isNotNull] ? NO : YES;
|
||||
if (!isNewRecord)
|
||||
{
|
||||
if ([[self deletionOfContentWithName:_name] intValue] > 0)
|
||||
if ([[currentRow objectForKey: @"c_deleted"] intValue] > 0)
|
||||
{
|
||||
[self _purgeRecordWithName: _name];
|
||||
isNewRecord = YES;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* check whether sequence matches */
|
||||
if (_baseVersion != 0 /* use 0 to override check */) {
|
||||
if (_baseVersion != [storedVersion unsignedIntValue]) {
|
||||
|
||||
Reference in New Issue
Block a user