Skip to content

Commit

Permalink
code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Aug 1, 2023
1 parent d3c6989 commit f400d42
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using starsky.foundation.database.Models;
Expand Down Expand Up @@ -141,6 +142,8 @@ public static FileIndexItem Set(FileIndexItem? sourceIndexItem, string fieldName
/// </summary>
/// <param name="fieldName">name e.g. Tags</param>
/// <returns>bool, true=exist</returns>
[SuppressMessage("Usage", "Collection-specific Exists " +
"method should be used instead of the Any extension.")]
public static bool CheckIfPropertyExist(string fieldName)
{
PropertyInfo[] propertiesA = new FileIndexItem().GetType().GetProperties(
Expand Down
6 changes: 3 additions & 3 deletions starsky/starsky.foundation.sync/SyncServices/SyncFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ internal async Task CompareFolderListAndFixMissingFolders(List<string> subPaths,
{
if ( subPaths.Count == folderList.Count ) return;

foreach ( var path in subPaths.Where(path => folderList.All(p => p.FilePath != path) &&
foreach ( var path in subPaths.Where(path => folderList.TrueForAll(p => p.FilePath != path) &&
_subPathStorage.ExistFolder(path) && !_syncIgnoreCheck.Filter(path) ) )
{
await _query.AddItemAsync(new FileIndexItem(path)
Expand All @@ -155,7 +155,7 @@ internal async Task<List<FileIndexItem>> AddParentFolder(string subPath, List<Fi
// used to check later if the item already exists, to avoid duplicates
var filePathsAllResults = allResults.Select(p => p.FilePath).ToList();

if ( allResults.All(p => p.FilePath != subPath))
if ( allResults.TrueForAll(p => p.FilePath != subPath))
{
var subPathStatus = _subPathStorage.IsFolderOrFile(subPath);
var exifStatus = subPathStatus ==
Expand Down Expand Up @@ -301,7 +301,7 @@ internal static List<FileIndexItem> PathsToUpdateInDatabase(
var resultDatabaseItems = new List<FileIndexItem>(databaseItems);
foreach ( var path in pathsOnDisk )
{
var item = databaseItems.FirstOrDefault(p => string.Equals(p.FilePath, path, StringComparison.InvariantCultureIgnoreCase));
var item = databaseItems.Find(p => string.Equals(p.FilePath, path, StringComparison.InvariantCultureIgnoreCase));
if (item == null ) // when the file should be added to the index
{
// Status is used by MultiFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal async Task<List<FileIndexItem>> MultiFile(List<string> subPathInFiles,
var resultDatabaseItems = new List<FileIndexItem>();
foreach ( var path in subPathInFiles )
{
var item = databaseItems.FirstOrDefault(p =>
var item = databaseItems.Find(p =>
string.Equals(p.FilePath, path, StringComparison.InvariantCultureIgnoreCase));
if (item == null ) // when the file should be added to the index
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal async Task<List<FileIndexItem>> SingleFile(string subPath,
ISynchronize.SocketUpdateDelegate? updateDelegate = null)
{
// when item does not exist in db
if ( dbItems?.FirstOrDefault(p => p.FilePath == subPath) == null )
if ( dbItems?.Find(p => p.FilePath == subPath) == null )
{
return await SingleFile(subPath);
}
Expand Down Expand Up @@ -91,7 +91,7 @@ internal async Task<List<FileIndexItem>> SingleFile(string subPath,
scanItems.Add(item);
}

foreach ( var item in dbItems.Where(item => scanItems.All(p => p.FilePath != item.FilePath)) )
foreach ( var item in dbItems.Where(item => scanItems.TrueForAll(p => p.FilePath != item.FilePath)) )
{
scanItems.Add(item);
}
Expand Down
3 changes: 3 additions & 0 deletions starsky/starsky/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -13,6 +14,8 @@ namespace starsky
{
public static class Program
{
[SuppressMessage("Usage", "S6603: The collection-specific TrueForAll " +
"method should be used instead of the All extension")]
public static async Task Main(string[] args)
{
var appSettingsPath = Path.Join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ const ListImage: React.FunctionComponent<IListImageProps> = memo((props) => {
);
}

const className = error
? `img-box--error img-box--${props.imageFormat}`
: isLoading
? "img-box img-box--loading"
: "img-box";
let className = "img-box";
if (error) {
className += ` img-box--error img-box--${props.imageFormat}`;
} else if (isLoading) {
className += " img-box--loading";
}

return (
<div ref={target} className={className}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const ForceSyncWaitButton: React.FunctionComponent<
ForceSyncWaitButtonPropTypes
> = ({ propsParentFolder, historyLocationSearch, callback, dispatch }) => {
function forceSync(): Promise<IConnectionDefault> {
const parentFolder = propsParentFolder ? propsParentFolder : "/";
const parentFolder = propsParentFolder ?? "/";
setIsLoading(true);
new FileListCache().CacheCleanEverything();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const ModalArchiveSynchronizeManually: React.FunctionComponent<
function removeCache() {
setIsLoading(true);
new FileListCache().CacheCleanEverything();
const parentFolder = props.parentFolder ? props.parentFolder : "/";
const parentFolder = props.parentFolder ?? "/";
FetchGet(
new UrlQuery().UrlRemoveCache(new URLPath().encodeURI(parentFolder))
).then((_) => {
Expand All @@ -106,7 +106,7 @@ const ModalArchiveSynchronizeManually: React.FunctionComponent<
const [geoSyncPercentage, setGeoSyncPercentage] = useState(0);

function geoSync() {
const parentFolder = props.parentFolder ? props.parentFolder : "/";
const parentFolder = props.parentFolder ?? "/";

const bodyParams = new URLSearchParams();
bodyParams.set("f", parentFolder);
Expand All @@ -116,7 +116,7 @@ const ModalArchiveSynchronizeManually: React.FunctionComponent<
}

function fetchGeoSyncStatus() {
const parentFolder = props.parentFolder ? props.parentFolder : "/";
const parentFolder = props.parentFolder ?? "/";
FetchGet(
new UrlQuery().UrlGeoStatus(new URLPath().encodeURI(parentFolder))
).then((anyData) => {
Expand All @@ -136,15 +136,15 @@ const ModalArchiveSynchronizeManually: React.FunctionComponent<
useInterval(() => fetchGeoSyncStatus(), 10000);

function manualThumbnailSync() {
const parentFolder = props.parentFolder ? props.parentFolder : "/";
const parentFolder = props.parentFolder ?? "/";
const bodyParams = new URLSearchParams();
bodyParams.set("f", parentFolder);
setIsLoading(true);

FetchPost(
new UrlQuery().UrlThumbnailGeneration(),
bodyParams.toString()
).then((anyData) => {
).then((_) => {
setTimeout(() => {
setIsLoading(false);
props.handleExit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const PreferencesAppSettings: React.FunctionComponent<any> = (_) => {

async function changeSetting(value: string, name?: string): Promise<number> {
const bodyParams = new URLSearchParams();
bodyParams.set(name ? name : "", value);
bodyParams.set(name ?? "", value);
const result = await FetchPost(
new UrlQuery().UrlApiAppSettings(),
bodyParams.toString()
Expand Down

0 comments on commit f400d42

Please sign in to comment.